Info

此问题已关闭。 请重新打开它进行编辑或回答。

plotting 3d graph in matlab

1 次查看(过去 30 天)
sumeet
sumeet 2017-9-30
关闭: MATLAB Answer Bot 2021-8-20
hi,
I want to plot a function on z axis x and y can vary from 0 to 1 .
Two constants c_one and c_two are fed by user.
f(z)=(c_one*x + c_two *y)/(x+y)
So I tried
[X,Y] = meshgrid(0.1:0.1:1,0.1:0.1:1);
Z = ((0.9*X) + (0.1*Y))/(X+Y);
Here i took c_one=0.9 , c_two=0.1
It should simply evaluate z for 100 pairs of (x,y).
I get the message
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.473412e-19.
Why does that happen ?
Also , can you suggest a better way to graphically show 100 values (I did surf(X,Y,Z)) ?
Thanks.

回答(1 个)

Star Strider
Star Strider 2017-9-30
Use element-wise operations:
c_one=0.9;
c_two=0.1;
f = @(x,y) (c_one.*x + c_two.*y)./(x+y)
[X,Y] = meshgrid(0.1:0.1:1,0.1:0.1:1);
Z = f(X,Y);
figure(1)
surf(X,Y,Z)
grid on
See the documentation on Array vs. Matrix Operations (link) for details.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by