Imaginary number to a power
Ältere Kommentare anzeigen
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...
Antworten (1)
Matt Fig
am 14 Apr. 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?
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!