Fitting model to data set by estimating parameters
Show older comments
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
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.
Accepted Answer
More Answers (0)
Categories
Find more on Model Order Reduction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!