Parameter fitting problem: I use lsqnonlin to fit 3 parameters into a system of ODES and everything works fine until I inserted a Confidence Interval as one of my coefficients.At that point the fitted parameter vector took only the initial guess

4 views (last 30 days)
Parameter fitting problem: I use lsqnonlin to fit 3 parameters into a system of ODES and everything works fine until I inserted a Confidence Interval as one of my coefficients.At that point the fitted parameter vector took only the initial guess
  2 Comments
Torsten
Torsten on 9 Nov 2018
Edited: Torsten on 9 Nov 2018
Commented by Helen Flountzi:
For example, this is one of my ODEs: dy(1)=h*(1-z)*N-lamda0*nsp_r*y(1)-(m+q)*y(1)+param2*y(4); if I replace z with z=0.289+(0.615-0.289)*rand; my fitting process provides as solution the initial param2(0)that I gave initially(I already tried to change the initial values &still the same)

Sign in to comment.

Accepted Answer

Torsten
Torsten on 9 Nov 2018
Edited: Torsten on 9 Nov 2018
Each time your ODE function is called, "rand" takes a different value between 0 and 1. This makes it impossible for the ODE solver to get a solution of your ODE and for the fitting tool to determine optimal parameters. So it gives up and returns the initial guesses.
Call the fitting tool for different, but fixed values for z in a loop and see how the optimal parameters change.
Best wishes
Torsten.
  4 Comments
helen flountzi
helen flountzi on 13 Nov 2018
The problem is that I have a main script, which calls one function and this function calls another function, which contains the ODEs that I m trying to solve and z is one of the coefficients and it needs to be replaced there after it's random selection in order to be evaluated from lsqnonlin!I wrote the code you suggested it in my script, but now it gives the message "Undefined function or variable 'z_actual', which means that somehow z_actual is not replaced in the equations...any idea for this?
Torsten
Torsten on 13 Nov 2018
Edited: Torsten on 13 Nov 2018
Somewhere in your code you have to call "lsqnonlin". That's where you have to insert the above loop. This way, z_actual is passed to the function "fun_lsqnonlin" of lsqnonlin. In this function, you somehow have to call an ODE integrator (e.g. ODE45). Pass z_actual a second time to the function "fun_ODE_integrator" where you define your ODE in the same way as you did for lsqnonlin. Then you can use z_actual as coefficient in your ODE function.
Or, although usually not recommended: Define z_actual as global and insert
global z_actual
in the function where you call lsqnonlin and in the function where you supply the ODE.

Sign in to comment.

More Answers (1)

george hargenrader
george hargenrader on 11 Nov 2020
How does inserting a range of starting values for one parameter equate to a confidence interval? What information do you gain by doing this?

Community Treasure Hunt

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

Start Hunting!