1

I'm having trouble graphing using Matlab, and was hoping someone could help. I just want to hand the program a function like $z=x^2-3xy+2$, or whatever, and have Matlab generate a 3D graph. From the tutorials I've seen online, it seems like this is difficult. Can I not just hand the program that equation and the domain that I want, and have it generate a graph? What code will generate that graph? Thanks!

dan
  • 427

2 Answers2

3

As an example, lets plot the function in the interval $x=[-2;2], y=[-2;2]$. As mentioned in the comments, this can be achieved in Matlab by the code

[X,Y] = meshgrid(-2:.2:2, -2:.2:2);                                
Z = X.^2 - 3*X.*Y + 2;
surf(X,Y,Z)

It can also be done in Maple by the following code

plot3d(x^2 - 3*x*y, x=-2..2, y=-2..2);

which is probably more intuitive. At last, one can use Wolfram Alpha.

utdiscant
  • 3,201
  • thanks for the help. I used Maple at my last job, and so far I find it much more intuitive than Matlab. – dan Aug 17 '12 at 01:51
0

A simple way to do that is to use ezsurf:

ezsurf('x^2-3*x*y+2')

or fsurf in recent Matlab versions.

Luis Mendo
  • 1,834