Imaginary number to a power
古いコメントを表示
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...
回答 (1 件)
Matt Fig
2011 年 4 月 14 日
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?
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!