Display 3D graph for a function

1 view (last 30 days)
ly
ly on 15 Aug 2021
Edited: DGM on 15 Aug 2021
Display a 3D graph for a function
x3 = 0;
nc=10;
y1 = 43.5943 - 12.5921*x1 + 4.08342*x2 + 3.6128*x3 + 14.4637* x1^2 + 9.3*x1*x2+ 4.1225*x1*x3 + 12.5333*x2^2 +3.2325* x2*x3+ 15.7648* x3^2;
[x1,x2] = meshgrid((1.68*(-1:1/nc:1)),(1.68*(-1:1/nc:1)));
mesh (x1,x2,y1)
But I got a figure which is not similar to the example.
How to display a function correctly?

Accepted Answer

DGM
DGM on 15 Aug 2021
Edited: DGM on 15 Aug 2021
You probably weren't intending to use matrix operations there.
x3 = 0;
nc = 10;
[x1,x2] = meshgrid((1.68*(-1:1/nc:1)),(1.68*(-1:1/nc:1)));
% use .* and .^ for elementwise operations
y1 = 43.5943 - 12.5921*x1 + 4.08342*x2 + 3.6128*x3 ...
+ 14.4637*x1.^2 + 9.3*x1.*x2 + 4.1225*x1.*x3 ...
+ 12.5333*x2.^2 + 3.2325*x2.*x3 + 15.7648*x3.^2;
mesh (x1,x2,y1)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!