surf cannot be complex

1 visualizzazione (ultimi 30 giorni)
john birt
john birt il 3 Mag 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?

Risposta accettata

Matt Fig
Matt Fig il 3 Mag 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)

Più risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by