フィルターのクリア

Fitting model to data set by estimating parameters

13 ビュー (過去 30 日間)
Oskar
Oskar 2023 年 12 月 10 日
コメント済み: Star Strider 2023 年 12 月 13 日
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.

採用された回答

Star Strider
Star Strider 2023 年 12 月 10 日
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 件のコメント
Oskar
Oskar 2023 年 12 月 13 日
Thank you very much for that explaination. It solved the problem.
Star Strider
Star Strider 2023 年 12 月 13 日
As always, my pleasure!

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

その他の回答 (0 件)

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by