Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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!

share|improve this question
    
I suggest you to use the free software Maxima. –  Sigur Aug 17 '12 at 1:12
    
You've at least tried to read the docs? –  J. M. Aug 17 '12 at 1:21
    
Yes, I've read the docs. From the examples I've seen, it just seems unnecessarily difficult to generate a graph. –  dan Aug 17 '12 at 1:24
3  
The documentation for meshgrid has an example of creating a 3D graph in three lines of code (two, if you fold the second line into the third). It would be nice to not need to go through the motions of creating a meshgrid, but that's how it is in Matlab. –  Rahul Aug 17 '12 at 1:35
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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 1:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.