Ask Your Question
1

Isolines of piecewise linear function

asked 2014-01-15 07:47:34 +0100

paterijk gravatar image

Hi,

I'm trying to find out how to plot isolines (in 3D) of the following function :

z = 0.2 x + 0.8 y if x < y and z = 0.6 x+0.4 y if x >= y

Thanks in advance for any help,

Patrick

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-01-15 08:39:05 +0100

tmonteil gravatar image

updated 2014-01-15 10:08:09 +0100

First, you can define your function as follows:

sage: f = lambda x,y : 0.2*x + 0.8*y if x < y else 0.6*x + 0.4

Then, your question is not clear to me. If you want a 3D plot of the function, you can do:

sage: plot3d(f, [-10,10], [-10,10])

But if you want the isolines, then it is a 2D object not a 3D one, which you can get by:

sage: contour_plot(f, [-10,10], [-10,10])

You can get some fancy style output options by typing

sage: contour_plot?

If you want to immerse the contour plot in 3D along the graph of the function (as suggested in your comment), you can try something like:

sage: sum([implicit_plot3d(lambda x,y,z : f(x,y), [-10,10], [-10,10], [c,c+0.01], contour=c) for c in range(-10,10)])
edit flag offensive delete link more

Comments

Thanx for the quick answer. In fact, I need a mix of both plot3d and contour_plot : in the 3d plot, I would like to see a sample of lines having the same "z" values, instead of the surface. Best regards, Patrick

paterijk gravatar imagepaterijk ( 2014-01-15 09:01:24 +0100 )edit

I updated my answer to try to answer your comment.

tmonteil gravatar imagetmonteil ( 2014-01-15 10:06:04 +0100 )edit

That's exactly what I need, thank you ;-)

paterijk gravatar imagepaterijk ( 2014-01-15 10:11:22 +0100 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2014-01-15 07:47:34 +0100

Seen: 934 times

Last updated: Jan 15 '14