Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

plotting 3d graph in matlab

1 view (last 30 days)
sumeet
sumeet on 30 Sep 2017
Closed: MATLAB Answer Bot on 20 Aug 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.

Answers (1)

Star Strider
Star Strider on 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.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!