surf cannot be complex
3 次查看(过去 30 天)
显示 更早的评论
when i run this code
d = 0.0002;
g = 80;
t = 6;
k = 0.7;
m = 0;
i = (48*d.*t.^2*k.*(k-1).*(k-2).*g^((k-3)/k)-12*d.*k.*(k-1).*g.^((k-2)/k)-16*d.*t.^4*k.*(k-1).*(k-2).*(k-3).*g^((k-4)/k))+3*(2*d.*k.*g.^((k-1)/k)-4*d.*t.^2*k.*(k-1).*g.^((k-2)/k)).^2+4*(8*d.*t.^3*k.*(k-1).*(k-2).*g.^((k-3)/k)-12*d.*t.*k.*(k-1).*g.^((k-2)/k)).*(2.*t.*d.*k.*g.^((k-1)/k)+m)+6.*(2*d.*k.*g.^((k-1)/k)-4*d.*t.^2.*k.*(k-1).*g.^((k-2)/k)).*(2*t.*d.*k.*g.^((k-1)/k)+m).^2+(2*t.*d.*k.*g.^((k-1)/k)+m)^4;
h = 2*d.*k.*(g.^(1/k)-2*t.^2*(k-1)).*g.^((k-2)/k);
Z = i./(h.^2);
it works, however when i try and let 'd' and 'g' be vectors with the aim of plotting a 3d plot for Z. With this code
d1 = 0.0002:0.00001:0.0004;
g1 = 70:1:90;
[d,g] = meshgrid(d1,g1);
t = 6;
k = 0.7;
m = 0;
i = (48*d.*t.^2*k.*(k-1).*(k-2).*g^((k-3)/k)-12*d.*k.*(k-1).*g.^((k-2)/k)-16*d.*t.^4*k.*(k-1).*(k-2).*(k-3).*g^((k-4)/k))+3*(2*d.*k.*g.^((k-1)/k)-4*d.*t.^2*k.*(k-1).*g.^((k-2)/k)).^2+4*(8*d.*t.^3*k.*(k-1).*(k-2).*g.^((k-3)/k)-12*d.*t.*k.*(k-1).*g.^((k-2)/k)).*(2.*t.*d.*k.*g.^((k-1)/k)+m)+6.*(2*d.*k.*g.^((k-1)/k)-4*d.*t.^2.*k.*(k-1).*g.^((k-2)/k)).*(2*t.*d.*k.*g.^((k-1)/k)+m).^2+(2*t.*d.*k.*g.^((k-1)/k)+m)^4;
h = 2*d.*k.*(g.^(1/k)-2*t.^2*(k-1)).*g.^((k-2)/k);
Z = i./(h.^2);
surf(d,g,Z)
It then tells me that
??? Error using ==> surf at 78
X, Y, Z, and C cannot be complex.
and the values min/max values for 'i' are then NAN?
I fail to see what I have done wrong as if i test the i values with different combinations of 'd' and 'g' in my required intervals the value of 'i' never goes NAN or never goes complex.
What have I done wrong?
0 个评论
采纳的回答
Matt Fig
2011-5-3
You forgot a couple of dots (g^ -> g.^) in your code.
d1 = 0.0002:0.00001:0.0004;
g1 = 70:90;
[d,g] = meshgrid(d1,g1);
t = 6;
k = 0.7;
m = 0;
I = (48*d.*t.^2*k.*(k-1).*(k-2).*g.^((k-3)/k)-12*d.*k.*(k-1).*...
g.^((k-2)/k)-16*d.*t.^4*k.*(k-1).*(k-2).*(k-3).*g.^((k-4)/k))+...
3*(2*d.*k.*g.^((k-1)/k)-4*d.*t.^2*k.*(k-1).*g.^((k-2)/k)).^2+...
4*(8*d.*t.^3*k.*(k-1).*(k-2).*g.^((k-3)/k)-12*d.*t.*k.*(k-1).*...
g.^((k-2)/k)).*(2.*t.*d.*k.*g.^((k-1)/k)+m)+6.*(2*d.*k.*...
g.^((k-1)/k)-4*d.*t.^2.*k.*(k-1).*g.^((k-2)/k)).*(2*t.*d.*k.*...
g.^((k-1)/k)+m).^2+(2*t.*d.*k.*g.^((k-1)/k)+m)^4;
h = 2*d.*k.*(g.^(1/k)-2*t.^2*(k-1)).*g.^((k-2)/k);
Z = I./(h.^2);
surf(d,g,Z)
0 个评论
更多回答(1 个)
Sean de Wolski
2011-5-3
DON'T NAME YOUR VARIABLES 'i'!!
It's the sqrt(-1) and it's probably what's messing you up!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!