Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

Contour plot restricted to a region defined by multiple inequalities

asked 8 years ago

Slimane gravatar image

I'm trying to use contour_plot for plotting contours defined only in a region of the parameter space, namely only in the triangle defined by the vertices (0,0),(1/2,3/2),(1,0). The faces of this triangle are defined by the intersections of the x-axis and the lines of equation y=3x and y=3x+3.

Contour_plot has the nice option region, but it seems that region only accepts one condition, i.e. only one boundary because the documentation specifies that region must be of the form f(x,y) and this is interpreted by the code of countour_plot as f(x,y)>0, i.e. countour_plot plots all points such that f(x,y)>0. Is there a way to do what I need with this version of contour_plot?

The following represents what I’d like to do but it does not work. It does not throw an error but only takes into account the first condition

contour_plot((x^2) * cos(x*y), (x,-10,5), (y,-5,5), region=(-sqrt(3)*x-y and -sqrt(3)*x+sqrt(3)-y), fill=True, contours=30)

Note that there are other imperfect solutions to this problem like using a white polygon to hide the part of the plot I do not want to see. However, this "solution" is not desirable because the maximum and minimum values of contour_plot will not be defined with respect to the region I am trying to show (I hope this is clear; I can show an example if this is not).

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

updated 8 years ago

Since both sqrt(3)*x-y and -sqrt(3)*x+sqrt(3)-y must be positive to define your region, multiply the two together:

var('x y')
contour_plot((x^2) * cos(x*y), (x,0,1), (y,0,sqrt(3)/2),
             region=(sqrt(3)*x-y)*(-sqrt(3)*x+sqrt(3)-y), fill=True, contours=30)

Here's a live example.

Preview: (hide)
link

Comments

This solves the problem, thanks! Also, one might still want to use polygon to have better-looking boundaries.

Slimane gravatar imageSlimane ( 8 years ago )

You can make the boundaries smoother by increasing plot points: plot_points=500

paulmasson gravatar imagepaulmasson ( 8 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 467 times

Last updated: Nov 16 '16