Need help for ploting 3D graphic

hello.. i want to plot 3D graphic but i'm confused...here's my M-file code:
%boundary for x
x = 80:0.1:100;
%boundary for y
y = 14:0.1:16;
[x,y] = meshgrid (80:0.1:100)
%function z
z = 3.1396 - 0.0235*x - 0.2759*y + 0.0008*x*y + 0.0001*x^2 + 0.0007*y^2;
mesh(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
colormap(jet)
well i get the graphic..but not as I expected. Its a flat one. I want a wavy one. Maybe something wrong with my boundaries setup? The point is:
80 < x < 100 ,
14 < y < 16 and,
z = 3.1396 - 0.0235*x - 0.2759*y + 0.0008*x*y + 0.0001*x^2 + 0.0007*y^2;
can someone help me? Tahnk you

Answers (1)

hi Rudi Martin,
the two variables x and y have different boundaries, but when you called the command meshgrid, they all have the same boundaries 80: 100, u have to use the syntax :
[x,y]=meshgrid(xi:step:xf,yi:step:yf);
But they must have equal length to avoid the "Matrix dimensions must agree " error, then you can choose for example 200 points using the command 'linspace' (which is linear spacing function):
X=linspace(80,100,N);
Y=linspace(14,16,N);
[x,y]=meshgrid(X,Y);
z = 3.1396 - 0.0235.*x - 0.2759.*y + 0.0008.*x.*y + 0.0001*(x.^2) + 0.0007*(y.^2);
figure,
mesh(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
colormap(jet)
The function z is still flat which makes clear that the issue is not in boundaries, try to verify the coefficients related to 2nd order .

This question is closed.

Products

Asked:

on 9 Jul 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!