Does the surf command have plotting errors?

1 view (last 30 days)
The following code does not produce the correct plot:
Trial>> [X,Y]=meshgrid(-2.5:0.2:2.5)
Trial>> Z=(X.^2+3*Y.^2)*exp(1-X.^2-Y.^2);
Trial>> surf(X,Y,Z)

Accepted Answer

Star Strider
Star Strider on 9 Jan 2016
You have to do element-wise multiplication in your ‘Z’ assignment:
Z=(X.^2+3*Y.^2).*exp(1-X.^2-Y.^2);
^ <ADD DOT OPERATOR HERE
[X,Y]=meshgrid(-2.5:0.2:2.5);
Z=(X.^2+3*Y.^2).*exp(1-X.^2-Y.^2);
figure(1)
surf(X,Y,Z)
grid on

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!