Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

plotting 3d graph in matlab

1 vue (au cours des 30 derniers jours)
sumeet
sumeet le 30 Sep 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

Star Strider
Star Strider le 30 Sep 2017
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.

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by