initial value problem and curve fitting

2 views (last 30 days)
but I still don't understand. I've tried the syntax but it doesn't work
function dydt = f(t,y,par)
a=par(1);
b= par(2);
dydt (1) = par(1)*y + par (2)*y.^2;
end
also given is an intial value problem
y' = ay + by² , y(0) = y0
with unknown parameter a,b,y0
the measurement value von t and y is also given.
How can I find the parameter a,b and y0 with ode45 and lsqcurvefit?
I also read the matlab documentation for ode45, the example shows that the using of ode45 to find t and y. but in my case, it's reverse. I have the t and y but don't have the parameter of y'.
funpar = @(par,ydata) par(1)*ydata + par(2)*ydata.^2;
par0 = [1 1];
par = lsqcurvefit(funpar,par0,tdatata,ydata);
Local minimum found.
Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.
Optimization completed: The first-order optimality measure, 4.003694e-07,
is less than options.OptimalityTolerance = 1.000000e-06.
  3 Comments
Shabrina Nurul Izzanisa
Shabrina Nurul Izzanisa on 30 Jul 2020
Hallo John, yes this is a homework, i've read several post in this forum and tried but still don't get the solution.
also, I forgot to write my code in the question before, and now it's updated.
do u have any other hint for me?
thanks for your response
John D'Errico
John D'Errico on 30 Jul 2020
The point is, you can solve the ODE. There is an analytical solution. Then you never need to use ODE45 at all. This is just then a simple call to lsqcurvefit.
By the way, there are some problem sets of parameters. For example,
  1. when y0 is 0, then the solution is y(t) == 0.
  2. when y0 = -a/b, the solution is also fixed at y(t) = -a/b.
Of course, dsolve told me that. But dsolve also told me the third solution for other fully general values of y0.
Anyway, I assume you have explicitly been told to use ode45 AND lsqcurvefit, as this is homework. If not then you would just have taken my advice.
So, do this: Suppose you KNEW the values of a,b, and y0. Could you then solve the ODE using ODE45? DO IT. Pick some values for a,b, and y0. SOLVE IT. Use ODE45. Make sure that ODE45 returns values at the list of times where you have data. Just pretend you knew the values of a,b, and y0.
That is step 1. Break large problems into small problems. Then solve the small problems.
Step 2. Put that solution into a function, where you can then pass in ANY set of values of a, b, y0.
Step 3. Can you call lsqcurvefit on the function from step 2?
I'm sorry, but I won't do your homework for you. As it is, I've given you far more of an outline for how to do this than I should.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!