Imaginary number to a power
Mostrar comentarios más antiguos
I've been getting inconsistent results from a simple piece of code: 'i^3'. I expect this to yield 0,-1.0i. I get this result some times but many times I get -1.0 instead. Prior to this I enter 'i=sqrt(-1)' to ensure i is properly defined. I've tried 'clear all', 'clear functions', and exiting MATLAB and getting back in but still get inconsistent results.
Any idea why this happens? I'm running R2008b (7.7.0.471). Thanks...
Respuestas (1)
Matt Fig
el 14 de Abr. de 2011
No problem here:
clear i
correct_answer = i^3 % Verify this first!
for ii = 1:100000,
if ~isequal(i^3,correct_answer)
disp('Uh-oh')
break
end
end
Are you sure you haven't been using i as a loop variable?
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!