Trying to fit parameters for an ODE model to real data using lsqcurvefit

조회 수: 17 (최근 30일)
Hi! I'm trying to fit parameters for an ODE model to real data using lsqcurvefit. The issue I'm having is that lsqcurvefit always returns the initial guess. I've looked at previous forum posts similar to this problem and found a function to use as an example (Igor_Moura.m) and I can't seem to find any real differences between the code I've constructed and that example. I think the issue may be a result of the parameter not being able to change once fed into the ODE function, but I'm not sure how to fix it if that's the case. (My file is called SIRpvectorattempt.m)
function SIRpvectorattempt
%define function so solve for data
function G = SIRsolve(pvector,t)
x0=[0,5.704*10^6];
%ODE solver
[T,x]= ode45(@ODESIRlsq,t,x0);
function dx = ODESIRlsq(t,x)
%x(1)=i(t), x(2)=s(t), pvector(1)=lambda, pvector(2)=mu
%define ODE's
dx=zeros(2,1);
dx(1)=pvector(1).*x(2).*x(1)-pvector(2).*x(1);
dx(2)=-pvector(1).*x(2).*x(1);
end
%infected and susceptible populations over timeframe
G=x; % (:,1:2);
end
t=[1;2;3;4;5;6;7;8;9;10];
%real data from xcel file
ydata=zeros(10,2);
ydata(:,1) = xlsread('Covid Case Data Sorted SIR with columns for singapore','Singapore','H2:H11'); %453 itreal
ydata(:,2) = xlsread('Covid Case Data Sorted SIR with columns for singapore','Singapore','I2:I11'); %streal
pvecguess = [1;1];
pvector = lsqcurvefit(@SIRsolve,pvecguess,t,ydata)
end

채택된 답변

Star Strider
Star Strider 2021년 5월 8일
‘... I can't seem to find any real differences between the code I've constructed and that example.’
I agree that the initial parameter estimates are likely the problem. If you have the Global Optimization Toolbox, this version of that same code (attached), using the ga function to estimate the parameters, will likely do what you want. (This will require a few tweaks for your current code to work with ga.) It may take a few runs until ga discovers a suitable set of parameters, however it will likly succeed.
Note that if you want to use lsqcurvefit to produce results that could be used with nlparci to estimate the parameter confidence intervals (and to slightly tweak the paramters themselves), use the parameter estimates that ga produces as the initial parameter estimates for lsqcurvefit.
  댓글 수: 4
Brian Voke
Brian Voke 2021년 5월 9일
Changing the ode solver to ode15s worked, thanks so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by