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!