题目:
计算带有乘性噪声的一维型积分,即
其真解为
一类平衡法数值格式为
Euler方法格式为
我们计算当时,比较两种方法的数值解逼近真解的情况。
程序:
randn('state',100)
sigma = 4;T = 1;Xzeros = 1;
N = 1.5e+5;
dt = 1/N;
dW = sqrt(dt)*randn(1,N);%Brownian increments
W = cumsum(dW);
%----------------true solution
Xtrue = Xzeros*exp(sigma*W-sigma^2/2*[dt:dt:T]);
R = 5;
Dt = R*dt;
L = N/R;
XE = zeros(1,L);
Xtemp = Xzeros;
%----------------Euler explicit method
for j = 1:L
Winc = sum(dW(R*(j-1)+1:R*j));
Xtemp = Xtemp+sigma*Xtemp*Winc;
XE(j) = Xtemp;
end
%---------------The balanced method
XB = zeros(1,L);
Xtemp = Xzeros;
for j = 1:L
Winc = sum(dW(R*(j-1)+1:R*j));
Xtemp = ((1+sigma*abs(Winc))*Xtemp+sigma*Xtemp*Winc)/(1+sigma*abs(Winc));
XB(j) = Xtemp;
end
figure
plot([(0:Dt:T)],[Xzeros,XE],'r-*');
hold on;
plot([0:dt:T],[Xzeros Xtrue],'k--');
legend('显式Euler数值解','真解');
figure
plot([(0:Dt:T)],[Xzeros,XB],'y+'),
hold on
plot([0:dt:T],[Xzeros Xtrue],'k--');
legend('平衡法数值解','真解');
erro=max(abs([Xzeros,XE]-[Xzeros,XB]))
结果:
平衡方法和Euler方法的数值解图像和真解图像基本吻合,通过这两种方法得到数值解相差0.0830。