フィルターのクリア

Stochastic delay differantial equations

14 ビュー (過去 30 日間)
miray boldan
miray boldan 2021 年 6 月 21 日
コメント済み: miqin 2023 年 1 月 2 日
ı write this matlab code but it doesnt work.
% Euler-Maruyama method on linear SDE Stock Price.
%SDE is dS= ((mu*S)+(c*S(t-tau)-d) dt + ((a*S)+(b*S(t-tau))dW, S(0) = Szero,
%where mu = -3, c = 2e^-1 , d = 3-2e^-1 , a= 0.1 , b= 0.1 , tau = 1 and Szero = 100.
%Discretized Brownian path over [0,1] has dt = 2^(-8).
%Euler-Maruyama uses timestep R*dt.
randn('state',100)
mu = -3; a = 0.1 ; b = 0.1 ; Szero = 100;
T = 2; N = 2^8; dt = 1/N;
dW = sqrt(dt)*randn(1,N);
W = cumsum(dW);
%Strue = Szero*exp((mu-0.5*sigma^2)*([dt:dt:T])+sigma*W);
%plot([0:dt:T],[Szero,Strue],'m-'), hold on
R =8; Dt = R*dt; L = N/R;
Xem = zeros(1,L);
Xtemp = Szero;
linetypes={'b-','g--*'};
for j = 1:L
Winc = sum(dW(R*(j-1)+1:R*j));
Xtemp = Xtemp + Dt*mu*Xtemp + a*Xtemp*Winc;
Xem(j) = Xtemp;
end
plot([0:Dt:T],[Szero,Xem],'g--*'), hold off
legend(': Exact solution',': Euler-Maruyama')
xlabel('t','FontSize',12)
ylabel('S','FontSize',12,'Rotation',0,'HorizontalAlignment','right')
emerr = abs(Xem(end)-Strue(end))
what is my mistake?

回答 (1 件)

Divija Aleti
Divija Aleti 2021 年 6 月 24 日
Hi Miray,
The error is occurring in the line where you are using the plot function. This is because the values you have given to the function are of different lengths.
0:Dt:T has 65 elements whereas [Szero,Xem] has 33 elements.
To use the plot function, both these vectors should be of the same length.
I suggest you to review your problem statement, all the variable values and the code you have written to figure out which of the above vectors should be changed.
Hope this helps!
Regards,
Divija
  2 件のコメント
miqin
miqin 2023 年 1 月 2 日
Hi Divija,
It's nice to see your answer to the above question. I have a similar problem and want to get your help. The following is a stochastic differential equation group with time delay. I want to draw Fig. 4 but do not know how to write a Matlab program. Parameter values are as follows : r = 0.5 ; b = 0.6 ; c1 = 0.6 ; c2 = 0.5 ; d = 0.2 ; h = 0.8 ; β = 0.4.
Thanks!
Regards,
Cmq
miqin
miqin 2023 年 1 月 2 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by