surf cannot be complex

조회 수: 3(최근 30일)
john birt
john birt 2011년 5월 3일
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?

채택된 답변

Matt Fig
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)

추가 답변(1개)

Sean de Wolski
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!
  댓글 수: 2
john birt
john birt 2011년 5월 3일
thanks for that

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by