Plotting a 3D graph, incorrect solution.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pulkit Sharma
le 1 Mar 2018
Modifié(e) : Pulkit Sharma
le 2 Mar 2018
clc
clear
p00 = 553.6;
p10 = 23.56;
p01 = -24.72;
p20 = 212.1;
p11 = -301.9;
p02 = 186.9;
p30 = -2.76;
p21 = -1.261;
p12 = -7.603;
p03 = 11.23;
p40 = -54.55;
p31 = 30.5;
p22 = 10.44;
p13 = 36.48;
p04 = -48.45;
m=1;
n=1;
for x=-100:1:100
n=1;
for y=-100:1:100
Z(m,n)=p00+p10*x+p01*y+p20*x^2+p11*x*y+p02*y^2+p30*x^3+p21*x^2*y+p12*x*y^2+p03*x^3+p40*x^4+p31*y^3*y+p22*y^2*x^2+p13*x*y^3+p04*y^4
n=n+1;
end
m=m+1;
end
surf(x,y,Z)
title('3D PLOT'),xlabel('\bfX'),ylabel('\bfY'),zlabel('\bfZ')
This is the code that gets the Z array, which is to be plotted. Rewriting this in vectorised form, I have
clc
clear
x=-100:1:100;
y=-100:1:100;
p00 = 553.6;
p10 = 23.56;
p01 = -24.72;
p20 = 212.1;
p11 = -301.9;
p02 = 186.9;
p30 = -2.76;
p21 = -1.261;
p12 = -7.603;
p03 = 11.23;
p40 = -54.55;
p31 = 30.5;
p22 = 10.44;
p13 = 36.48;
p04 = -48.45;
[X Y]=meshgrid(x,y);
Z=p00+p10*X+p01*Y+p20*X^2+p11*X*Y+p02*Y^2+p30*X^3+p21*X^2*Y+p12*X*Y^2+p03*Y^3+p40*X^4+p31*X^3*Y+p22*X^2*Y^2+p13*X*Y^3+p04*Y^4
surf(X,Y,Z)
title('3D PLOT'),xlabel('\bfX'),ylabel('\bfY'),zlabel('\bfZ')
Why am I getting separate solutions for both, when the solution should be the one that I am getting from the second one. (solution here is the values in Z). Any help would be most appreciated.
Solved, I was not putting the dots before the product and power operators.
0 commentaires
Réponse acceptée
Seyedali Mirjalili
le 2 Mar 2018
The problem is that after exiting the for loops, x and y are both equal to 100. So, they are scalars and cannot be used in surf. The function surf requires 2D matrices.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!