clcclear 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:100Z(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;endsurf(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
clcclearx=-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^4surf(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.
Best Answer