필터 지우기
필터 지우기

iteration of parameter of a system of ode's using lsqnonlin, version2

조회 수: 1 (최근 30일)
helen flountzi
helen flountzi 2017년 1월 17일
답변: Matt J 2017년 1월 17일
I want to iterate a parameter estimation -for example 20 times, using different data points-which comes from lsqnonlin command.The parameter is used in a couple of ODEs.The first code is:
%%Main code
% Guess what beta might be. Note: lb = lower bound, ub = upper bound
beta0 = 0.001;
beta_lb = 0;
beta_ub = 0.01;
% This means that nothing is output to the display after the fit. Can be
% changed if necessary.
opts = optimset('display','off');
% Fit the parameter to the system of equations with this initial guess
fitted_parameter_beta = lsqnonlin(@(p) model_fit_r(p), beta0, beta_lb, beta_ub, opts);
% Display the fitted parameter, here, beta
disp('Fitted parameter beta')
disp(fitted_parameter_beta)
and the second file with the function is:
%%This file calculates the difference between the model and the data
function fitting_function = model_fit(p)
% Set the parameter to be fit (note that p can be a vector)
beta_fit = p;
% Data point - This is the data that the beta_fit parameter will try
% to fit to and it can be changed
_data = 0.11; %For example, 11% at end timepoint
tspan = 0:0.5:100;
y0 = [98, 2];
[~,y] = ode45(@(t,y) model_fitting_equations(t,y,beta_fit),tspan,y0);
calculation_model = y(end,2)/(y(end,1)+y(end,2));
% Find the difference between the model and the data -
fitting_function = calculated_by_model - _data;
end
  댓글 수: 1
Stephen23
Stephen23 2017년 1월 17일
편집: Stephen23 2017년 1월 17일
@helen flountzi: do not keep adding new questions to this forum with exactly the same question but more details. You can simply edit your question or add comments.
I deleted your other question which you edited away. Please do not edit away text of your question: this makes it hard for us to help you.

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2017년 1월 17일
Your code is difficult for me to follow, and you haven’t described what the problem is, only that you want to fit the points.
In ‘model_fit’, is ‘calculation_model’ the same as ‘calculated_by_model’ or something different? That could be the problem if they are supposed to be the same variable.
See if the approaches in:
or:
would help you do what you want.
  댓글 수: 2
helen flountzi
helen flountzi 2017년 1월 17일
yes it is the same, sorry for that and it is not the problem, I reasure you!The problem is that I want to repeat this estimation procedure many times and get many estimation, and I always get error messages
Star Strider
Star Strider 2017년 1월 17일
If you would be so kind as to share the error messages, it would be easier to help you.
Copy and paste all the red text of the error messages from the Command Window to a Comment here, and format them as [{}Code].

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2017년 1월 17일
One reason that you might be getting errors is because of lines like this
_data = 0.11;
Variable names in MATLAB are not allowed to begin with underscores.

Community Treasure Hunt

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

Start Hunting!

Translated by