Imaginary number to a power
Show older comments
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...
Answers (1)
Matt Fig
on 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?
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!