surf cannot be complex
조회 수: 1 (최근 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!
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!