surf cannot be complex

1 visualización (últimos 30 días)
john birt
john birt el 3 de Mayo de 2011
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?

Respuesta aceptada

Matt Fig
Matt Fig el 3 de Mayo de 2011
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)

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 3 de Mayo de 2011
DON'T NAME YOUR VARIABLES 'i'!!
It's the sqrt(-1) and it's probably what's messing you up!
  2 comentarios
Matt Fig
Matt Fig el 3 de Mayo de 2011
Fixed in the code below, thanks Sean de!
john birt
john birt el 3 de Mayo de 2011
thanks for that

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by