# Isolines of piecewise linear function

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 close merge delete

Sort by » oldest newest most voted

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)])

more

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