Assuming I have a discretized system of SDE of the form
x(:, t+1) = x(:, t) + f1(x(:, t)).*x(:, t)*dt + f2(x(:, t))./(x(:, t).*y(:, t))* sqrt(dt)*rand1;
y(:, t+1) = f2(x(:, t)).*y(:, t)./x(:, t)*dt + f1(x(:, t)).*y(:, t)*sqrt(dt)*rand2;
and I want to simulate the system using 10000 trajectories,
for Time t = 100 days, such that: From Monday to Friday,
f1(x(:, t)) = 2*x(:, t).^2./(y(:, t) + x(:, t) + c)
, and
f2(x(:, t)) = y(:, t).^2;
whereas, Saturdays and Sundays
f1(x(:, t)) = x(:, t)./y(:, t)
, and f2(x(:, t)) = y(:, t);
How can I simulate the SDE system?
Here is my approach
dt = 0.01;
time = 100;
num_iteration = ceil(time / dt);
num_trajectory = 10000;
%% Initial Values
y0 = 1;
x0 = 1;
y = zeros(num_trajectory, num_iteration) + y0;
x = zeros(num_trajectory, num_iteration) + x0;
days = 0;
for t=1: num_iteration
current_time = t * dt;
rand1 = randn(num_trajectory, 1);
rand2 = randn(num_trajectory, 1);
if ceil(current_time) == current_time
days = days+1;
if (mod(days, 7) | mod(days+1, 7)) == 0
f1 = 2*x(:, t).^2./(y(:, t) + x(:, t) + c);
f2 = y(:, t).^2;
else
f1 = x(:, t)./y(:, t);
f2 = y(:, t);
end
end
x(:, t+1) = x(:, t) + f1*x(:, t)*dt + f2/(x(:, t).*y(:, t))* sqrt(dt)*rand1;
y(:, t+1) = f2*y(:, t)./x(:, t)*dt + f1*y(:, t)*sqrt(dt)*rand2;
end