Borrar filtros
Borrar filtros

Fitting model to data set by estimating parameters

13 visualizaciones (últimos 30 días)
Oskar
Oskar el 10 de Dic. de 2023
Comentada: Star Strider el 13 de Dic. de 2023
I am trying to estimate the parameters in a model which is based on a system of ordinary differential equations. I have tried the following, but there is something wrong with my method. Here is some of the code for context
load('data.mat');
t = time;
T_exp = data(1,:);
I_exp = data(2,:);
p = 2.23 * 10 ^ - 2;
c = 0.1;
beta
T0 = 10000;
I0 = 0;
V0 = 0.05;
initial_values = [T0; I0; V0];
beta_initial_guess = 10 ^- 5;
delta_initial_guess = 0.04;
estimated_params = fminsearch(@(params) objective_function(params, t, initial_values, T_exp, I_exp), [beta_initial_guess, delta_initial_guess])
function error = objective_function(params, t, initial_values, T_exp, I_exp)
beta = params(1);
delta = params(2);
p = 2.23 * 10 ^ - 2;
c = 0.1;
[tSol, YSol] = ode45(@(t, Y) virus_solver(t, Y, beta, delta, p, c), t, initial_values);
% Model predictions
T_model = YSol(:, 1);
I_model = YSol(:, 2);
% Calculate the objective function (sum of squared differences)
error = sum((T_model - T_exp).^2) + sum((I_model - I_exp).^2);
end
function dYdt = virus_solver(t, Y, beta, delta, p, c)
T = Y(1);
I = Y(2);
V = Y(3);
dTdt = -beta * V * T;
dIdt = beta * T * V - delta * I;
dVdt = p * I - c * V;
dYdt = [dTdt; dIdt; dVdt];
end
Unrecognized function or variable 'beta_true'.
The error i am getting with this code is :
Unable to perform assignment because the size of the left
side is 1-by-1 and the size of the right side is 1-by-28.
Error in fminsearch (line 209)
fv(:,1) = funfcn(x,varargin{:});
Error in exercise_3_4_4 (line 24)
estimated_params = fminsearch(@(params) objective_function(params, t, initial_values, T_exp, I_exp), [beta_true, delta_true]);
Is this a good approach to estimate the parameters? Or am thinking about this all wrong.

Respuesta aceptada

Star Strider
Star Strider el 10 de Dic. de 2023
The calculated ‘YSol’ should return a (Nx3) matrix where ‘N’ equals ‘numel(t)’ so if it does not, you need to determine the reason. Common problems include ode45 (in this instance) stopping because it has encountered a singularity or other significant discontinuity, and returning a matrix that does not have the same row size as the data. I would need ‘data.mat’ to see what the problem is. (I have written a number of these sorts of parameter estimation solutions.)
Determining what the problem is requires running the code, and that requires ‘data.mat’.
  4 comentarios
Oskar
Oskar el 13 de Dic. de 2023
Thank you very much for that explaination. It solved the problem.
Star Strider
Star Strider el 13 de Dic. de 2023
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by