算例:
随机线性微分方程
真解为
用Euler-Maruyama方法得出数值解
程序:
randn('state',200)
lambda=4;
mu=1;
Xzero=1;
T=1;
N=2^8;
dt=1/N;
dW=sqrt(dt)*randn(1,N);
W=cumsum(dW);
Xture=Xzero*exp((lambda-0.5*mu^2)*([dt:dt:T])+mu*W);
plot([0:dt:T],[Xzero,Xture],'b-');
hold on
R=8;
Dt=R*dt;
L=N/R;
Xem=zeros(1,L);
Xtemp=Xzero;
for j=1:L
Winc=sum(dW(R*(j-1)+1:R*j));
Xtemp=Xtemp+Dt*lambda*Xtemp+mu*Xtemp*Winc;
Xem(j)=Xtemp;
end
plot([0:Dt:T],[Xzero,Xem],'r--');
hold off
xlabel('t','FontSize',12)
ylabel('X','FontSize',16,'Rotation',0,'HorizontalAlignment','right');
title('EM 方法')
legend('exact solution','EM solution')
error=abs(Xem(end)-Xture(end))
结果:
图像模拟基本一致,模拟效果较好,方法可行。