Plotting a surface in MATLAB

1 次查看(过去 30 天)
I would like to plot
f(x,y) = x^2*y/(x^2 + y^2)
How do I do this in matlab?
  2 个评论
sally_wu
sally_wu 2015-10-3
编辑:sally_wu 2015-10-3
Maybe like this?
x=2;
y=3;
f(x,y) = x^2*y/(x^2 + y^2);
linspace(x,y)
Anthont Goddard
Anthont Goddard 2015-10-3
I am just getting a load of text output. Not a 3d plot

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2015-10-3
You need to use the meshgrid (or equivalently, ndgrid) function:
x = linspace(-1, 1);
y = linspace(-2, 2);
[X,Y] = meshgrid(x,y);
f = @(x,y) x.^2.*y./(x.^2 + y.^2);
figure(1)
surf(X,Y,f(X,Y))
grid on
I created a function for ‘f’ here, but you could as easily use it simply as:
f = X.^2.*Y./(X.^2 + Y.^2);
and then plot as:
plot(X,Y,f)
I ‘vectorised’ your code to do element-wise operations. See the documentation on Array vs. Matrix Operations for a full discussion.
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by