1

I want to plot 2 3D planes for the equations given below :

x + y + z = 1
2x - y = 0

For 1st equation, I plotted it using meshgrid as :

[x y] = meshgrid(-5:0.5:5);  
z = 1 - x - y  
mesh(x,y,z)

But for 2nd equation, z is not given i.e. z can be anything, then how do I plot plane for this ?

Happy Mittal
  • 3,667
  • 12
  • 44
  • 60
  • A HOLD ON might work - http://www.mathworks.in/help/matlab/ref/hold.html – Divakar Mar 01 '14 at 12:13
  • look at the second answer: [How can I plot a 3D-plane in Matlab?](http://stackoverflow.com/questions/13464304/how-can-i-plot-a-3d-plane-in-matlab) and also [here](http://www2.math.umd.edu/~jmr/241/lines_planes.html)! – Robert Seifert Mar 01 '14 at 13:32
  • @Divakar : problem is not that, problem is I don't know how to create plane for 2nd equation, 1st equation was just for illustration. – Happy Mittal Mar 01 '14 at 16:00
  • @thewaywewalk : none of the link contains this type of equation. For 2nd equation, the plane is absolutely verttcal, in 2D setting, it is analogous to equation x=0, where we would plot y axis, and I even don't know how to do that. – Happy Mittal Mar 01 '14 at 16:01
  • When x=0, you plot the y-axis because it is true for all of y. Same here - you plot this plane across all of z. So choose a start and end point for z for your plot, and do the same as you did before. – Lazarus Mar 01 '14 at 17:43

1 Answers1

3

The comments are correct. It is more of a math problem. You draw a line 2x - y = 0 and translate it for any z value to create a plane.

[x, y] = meshgrid(-5:0.5:5);  
Zv = @(x,y) 1 - x - y;
mesh(x,y,Zv(x,y));

hold on

[x, z] = meshgrid(-5:0.5:5);
Yv = @(x) 2*x;
mesh(x,Yv(x),z);

hold off
ysakamoto
  • 2,512
  • 1
  • 16
  • 22