How should I set the value of u_tau?
Hello everyone, I would like to use pdepe for solving a SIR partial differential equations in one dimension with time lag, so it looks good. But there has been a problem setting the value of u_tau, resulting in a very different result than expected. I don’t know what’s wrong with the code.Here is the part of the code involved:
function u_tau = interpolate_history(history, x, t, tau)
% Interpolating function to get the state at time t – tau
t_target = t – tau;
if t_target < history.t(1)
% u_tau = squeeze(history.u(1, :, :)); % Out of history range, use first value
u_tau = 0;
else
% u_tau = interp1(history.t, squeeze(history.u(:, :, :)), t_target, ‘linear’, ‘extrap’);
u_tau = 0;
end
end
function u0 = SIRInitialConditions3(x)
S0 = 1.25;
I0 = 0.85;
R0 = 0.74;
u0 = [S0; I0; R0];
end
% This is the part of the main function that deals with u_tau
function [c,f,s] = SIRPDE3(x, t, u, DuDx)
global history;
S = u(1);
I = u(2);
R = u(3);
u_tau = interpolate_history(history, x, t, tau);
S_pre = u_tau(1);
end
% This is the part of the main function that deals with u_tau
function run()
xspan = linspace(0, 10, 100);
tspan = [0, 10, 50];
% Initialising the history
history = initialize_history(xspan, tspan, @SIRInitialConditions3);
sol = pdepe(0, @SIRPDE3, @SIRInitialConditions3, @SIRBoundaryConditions3, xspan, tspan);
I originally ran the simulation with the two equations commented above neither of which resulted in a trend over time, so I set all u_tau to 0. The trend over time then turned out to be correct, but the initial values of I and R were still 0, which was not the expected result. I think there might be something wrong with the part function u_tau = interpolate_history(history, x, t, tau), how should I change it?
Thanks to the community. :)Hello everyone, I would like to use pdepe for solving a SIR partial differential equations in one dimension with time lag, so it looks good. But there has been a problem setting the value of u_tau, resulting in a very different result than expected. I don’t know what’s wrong with the code.Here is the part of the code involved:
function u_tau = interpolate_history(history, x, t, tau)
% Interpolating function to get the state at time t – tau
t_target = t – tau;
if t_target < history.t(1)
% u_tau = squeeze(history.u(1, :, :)); % Out of history range, use first value
u_tau = 0;
else
% u_tau = interp1(history.t, squeeze(history.u(:, :, :)), t_target, ‘linear’, ‘extrap’);
u_tau = 0;
end
end
function u0 = SIRInitialConditions3(x)
S0 = 1.25;
I0 = 0.85;
R0 = 0.74;
u0 = [S0; I0; R0];
end
% This is the part of the main function that deals with u_tau
function [c,f,s] = SIRPDE3(x, t, u, DuDx)
global history;
S = u(1);
I = u(2);
R = u(3);
u_tau = interpolate_history(history, x, t, tau);
S_pre = u_tau(1);
end
% This is the part of the main function that deals with u_tau
function run()
xspan = linspace(0, 10, 100);
tspan = [0, 10, 50];
% Initialising the history
history = initialize_history(xspan, tspan, @SIRInitialConditions3);
sol = pdepe(0, @SIRPDE3, @SIRInitialConditions3, @SIRBoundaryConditions3, xspan, tspan);
I originally ran the simulation with the two equations commented above neither of which resulted in a trend over time, so I set all u_tau to 0. The trend over time then turned out to be correct, but the initial values of I and R were still 0, which was not the expected result. I think there might be something wrong with the part function u_tau = interpolate_history(history, x, t, tau), how should I change it?
Thanks to the community. 🙂 Hello everyone, I would like to use pdepe for solving a SIR partial differential equations in one dimension with time lag, so it looks good. But there has been a problem setting the value of u_tau, resulting in a very different result than expected. I don’t know what’s wrong with the code.Here is the part of the code involved:
function u_tau = interpolate_history(history, x, t, tau)
% Interpolating function to get the state at time t – tau
t_target = t – tau;
if t_target < history.t(1)
% u_tau = squeeze(history.u(1, :, :)); % Out of history range, use first value
u_tau = 0;
else
% u_tau = interp1(history.t, squeeze(history.u(:, :, :)), t_target, ‘linear’, ‘extrap’);
u_tau = 0;
end
end
function u0 = SIRInitialConditions3(x)
S0 = 1.25;
I0 = 0.85;
R0 = 0.74;
u0 = [S0; I0; R0];
end
% This is the part of the main function that deals with u_tau
function [c,f,s] = SIRPDE3(x, t, u, DuDx)
global history;
S = u(1);
I = u(2);
R = u(3);
u_tau = interpolate_history(history, x, t, tau);
S_pre = u_tau(1);
end
% This is the part of the main function that deals with u_tau
function run()
xspan = linspace(0, 10, 100);
tspan = [0, 10, 50];
% Initialising the history
history = initialize_history(xspan, tspan, @SIRInitialConditions3);
sol = pdepe(0, @SIRPDE3, @SIRInitialConditions3, @SIRBoundaryConditions3, xspan, tspan);
I originally ran the simulation with the two equations commented above neither of which resulted in a trend over time, so I set all u_tau to 0. The trend over time then turned out to be correct, but the initial values of I and R were still 0, which was not the expected result. I think there might be something wrong with the part function u_tau = interpolate_history(history, x, t, tau), how should I change it?
Thanks to the community. 🙂 pdepe, lag, diffusion equation, sir model MATLAB Answers — New Questions