Model fitting for real data using matlab lsqcurve
Show older comments
I have a program which I need an assistant.
I have a system of 5-ODe model and my excel file has multiple sheets and each sheet has multiple columns.
Sheet1 has confirmed case from each state in Nigeria and the last column is the total confirmed
Sheet2 has Recovered case from each state in Nigeria and the last column is the total Recovered
Here is the thing I need to do
1. Model fitting to real data (MATLAB Lsqcurve) for all parameters then for infected parameter
2. Forecasting with the parameters (to get the peak time of infected and time to end infection. The file above contains the model. There's no data for Susceptible and exposed. Please I will appreciate if you help me
Thanks
Answers (1)
Shlok
on 18 Oct 2024
Hi Aloke,
I understand that you want to fit a 5-ODE model to real data and then forecast infection trends. Here’s how you can achieve this:
- First, load your Excel data into MATLAB using “readtable”.
- Then, define your 5-ODE system in a MATLAB function (e.g., “odeModel”) that takes parameters and calculates how the infected group changes over time.
- Next, use “lsqcurvefit” to fit your model to the confirmed cases data. Start with an initial guess for your parameters (“initialParams”) and let “lsqcurvefit” optimize them based on the real data (e.g., “totalConfirmed”). For your time data, create a vector “tData” representing the days of your observations. Here’s a small snippet to guide you:
fittedParams = lsqcurvefit(@yourObjectiveFunction, initialParams, tData, totalConfirmed);
- Once you have the fitted parameters (“fittedParams”), simulate your model using ODE solver, like “ode45”. Define your time span for the simulation with “tSpan”, which can be a range of future days you want to forecast. Here’s how you can do it:
[tSol, ySol] = ode45(@(t, y) odeModel(t, y, fittedParams), tSpan, initialConditions);
- At the end, analyse the simulation results. Use “max(ySol(:, 3))” to find the peak of infected cases and check when infections drop below a certain threshold (for example, by comparing “ySol(:, 3)” to a small value) to determine when the infection ends.
Using this approach will help you identify the peak infection time and the end of the epidemic.
To know more about “lsqcurvefit” and ODE solvers, you can refer to the following documentation links:
- lsqcurvefit: https://www.mathworks.com/help/optim/ug/lsqcurvefit.html
- ode45: https://www.mathworks.com/help/matlab/ref/ode45.html
Hope this helps.
Categories
Find more on Ordinary Differential Equations 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!