clear;clc
x=[1.1:0.1:2];y=0.1:0.1:1;%起點終點和步長可以自己改
[X,Y]=meshgrid(x,y);
syms t;
f=t.^(X+Y*i-1)*exp(-t) %定義積分函數
ga=int(f,t,0,inf) %積分
vpa(f,6) %查看結果
結果在x=1.1時會出現錯誤,當x=1.1時,積分函數為:
t^(i/10 + 1)/exp(t)
t^(i/5 + 1)/exp(t)
t^((3*i)/10 + 1)/exp(t)
t^((2*i)/5 + 1)/exp(t)
t^(i/2 + 1)/exp(t)
t^((3*i)/5 + 1)/exp(t)
t^((7*i)/10 + 1)/exp(t)
t^((4*i)/5 + 1)/exp(t)
t^((9*i)/10 + 1)/exp(t)
t^(i + 1)/exp(t)
即其中的實部分本應為0.1,這裏卻為1;這是產生錯誤的原因,從而用下面的試算x=1.1的情況:
b=0.1+Y(:,1)*i
b =
0.1000 + 0.1000i
0.1000 + 0.2000i
0.1000 + 0.3000i
0.1000 + 0.4000i
0.1000 + 0.5000i
0.1000 + 0.6000i
0.1000 + 0.7000i
0.1000 + 0.8000i
0.1000 + 0.9000i
0.1000 + 1.0000i
>> c=t.^b*exp(-t)
c =
t^(i/10 + 1/10)/exp(t) %這裏的實部正確,為0.1=1/10;
t^(i/5 + 1/10)/exp(t)
t^((3*i)/10 + 1/10)/exp(t)
t^((2*i)/5 + 1/10)/exp(t)
t^(i/2 + 1/10)/exp(t)
t^((3*i)/5 + 1/10)/exp(t)
t^((7*i)/10 + 1/10)/exp(t)
t^((4*i)/5 + 1/10)/exp(t)
t^((9*i)/10 + 1/10)/exp(t)
t^(i + 1/10)/exp(t)
>> int(c,t,0,inf) %對x=1.1時積分
ans =
gamma(i/10 + 11/10)
gamma(i/5 + 11/10)
gamma((3*i)/10 + 11/10)
gamma((2*i)/5 + 11/10)
gamma(i/2 + 11/10)
gamma((3*i)/5 + 11/10)
gamma((7*i)/10 + 11/10)
gamma((4*i)/5 + 11/10)
gamma((9*i)/10 + 11/10)
gamma(i + 11/10)
>> vpa(ans,6) %查看積分結果
ans =
0.943739-0.0397233*i
0.921608-0.0760291*i
0.886905-0.106088*i
0.842395-0.128064*i
0.791143-0.141237*i
0.736052-0.145883*i
0.679561-0.143*i
0.623529-0.13399*i
0.569237-0.1204*i
0.517481-0.103723*i
這個結果是正確的了。這個結果與最上方的程序之間產生矛盾,為什麽會這樣我也沒有搞懂。