下面是我的MATLAB代碼來產生波形速度的虛部(c),使用函數oscalcpcf當雷諾數是249,我想運行波數(alpha)在0.1到2之間2.真的很簡單的MATLAB代碼與不合邏輯的結果
c1holder = [];
c2holder = [];
reyholder = [];
alphaholder = [];
wantedrey = [];
wantedalpha = [];
for Rey = 249
for alpha = 0.1:0.1:2
c1=oscalcpcf(Rey,alpha,100);
c2=oscalcpcf(Rey,alpha,200);
c1holder = [c1holder c1];
c2holder = [c2holder c2];
reyholder = [reyholder Rey];
alphaholder = [alphaholder alpha];
end
end
vectors = [c1holder' c2holder' reyholder' alphaholder'];
上面的代碼在我看來並不困難,但我的筆記本電腦對於雷諾數和阿爾法的一些配對變得怪異。只要命名其中的一個,Reynolds number = 249
和alpha = 0.3
。
當我運行上面的代碼,我得到c1 = 6.06002472332094E-08
和c2 = 0.0000010870344982811
。
現在是這個問題。如果我從步驟-0.1
從2
到0.1
,我得到c1 = -0.337584041016646
和c2 = 0.0000364854401656638
。
如果我是檢查使用oscalcpcf
,即oscalcpcf(249,0.3,100)
和oscalcpcf(249,0.3,200)
手動,我得到c1 = -0.337583911335139
和c2 = -0.337577395716528
。
我真的不知道這是怎麼回事,有人可以幫忙!
編輯
alpha: 2.000000000000000000000000000000
alpha: 1.899999999999999900000000000000
alpha: 1.800000000000000000000000000000
alpha: 1.700000000000000000000000000000
alpha: 1.600000000000000100000000000000
alpha: 1.500000000000000000000000000000
alpha: 1.399999999999999900000000000000
alpha: 1.299999999999999800000000000000
alpha: 1.200000000000000000000000000000
alpha: 1.100000000000000100000000000000
alpha: 1.000000000000000000000000000000
alpha: 0.899999999999999910000000000000
alpha: 0.799999999999999820000000000000
alpha: 0.699999999999999960000000000000
alpha: 0.599999999999999870000000000000
alpha: 0.500000000000000000000000000000
alpha: 0.399999999999999910000000000000
alpha: 0.299999999999999820000000000000
alpha: 0.199999999999999960000000000000
alpha: 0.099999999999999867000000000000
和0.1
到2
alpha: 0.100000000000000010000000000000
alpha: 0.200000000000000010000000000000
alpha: 0.300000000000000040000000000000
alpha: 0.400000000000000020000000000000
alpha: 0.500000000000000000000000000000
alpha: 0.599999999999999980000000000000
alpha: 0.700000000000000070000000000000
alpha: 0.800000000000000040000000000000
alpha: 0.900000000000000020000000000000
alpha: 1.000000000000000000000000000000
alpha: 1.100000000000000100000000000000
alpha: 1.200000000000000200000000000000
alpha: 1.300000000000000300000000000000
alpha: 1.400000000000000100000000000000
alpha: 1.500000000000000200000000000000
alpha: 1.600000000000000100000000000000
alpha: 1.700000000000000200000000000000
alpha: 1.800000000000000300000000000000
alpha: 1.900000000000000100000000000000
alpha: 2.000000000000000000000000000000
OMG,爲什麼我的電腦不能給出精確0.1
步驟時,我告訴它這樣做。功能oscalcpcf
對alpha
中的小改動非常敏感,當我檢查我的腳本使用的這些值時,如果我通過oscalcpcf
手動執行該操作,它將會匹配。你能否建議我的電腦給出精確的步驟0.1
?謝謝。
不知道'oscalcpcf'在做什麼,我們只能猜測。根據函數對輸入的敏感程度,你的問題可能是精確的。嘗試添加'disp(['alpha:'sprintf('%。30f',alpha)]);'到你的內部for循環來查看'alpha'的實際值是什麼。 – Deve
實際上,一旦您瞭解計算機如何進行算術運算,完全符合邏輯的結果。 – 2012-09-01 13:55:15