求解随机微分方程
实验结果如下:
1.当时
2.当时
3.当时
误差结果:
程序代码:
clear all;
randn('state',100)
%lambda=1;
%mu=1;
%lambda=1.5;
%mu=1.5;
lambda=2;
mu=2;
X_0=1;
T=1;
N=2^8;
dt=1/N;
dW=sqrt(dt)*randn(1,N);
W=cumsum(dW);
E_X=X_0*exp((lambda-0.5*mu^2)*([dt:dt:T])+mu*W);
plot([0:dt:T],[X_0,E_X],'r-');
hold on
R=8;
Dt=R*dt;
L=N/R;
X=zeros(1,L);
Xtemp=X_0;
for j=1:L
Winc=sum(dW(R*(j-1)+1:R*j));
Xtemp=Xtemp+Dt*lambda*Xtemp+mu*Xtemp*Winc;
X(j)=Xtemp;
end
E_X;
plot([0:Dt:T],[X_0,X],'b--*');
hold off
xlabel('t','FontSize',12);
ylabel('X','FontSize',16,'Rotation',0,'HorizontalAlignment','right');
error=abs(X(end)-E_X(end))