Ode system solution with unknown constant
4 views (last 30 days)
Show older comments
ana ramirez de las heras
on 7 Dec 2020
Commented: Star Strider
on 9 Dec 2020
I'm trying to obtain and plot a function that adjusts to my data. I have a table with time, position and velocity, and an ode function which I have rewritten as a system:
ydot(1) = y(2)
ydot(2) = -a*y(2) - b*y(1) + c*cos(wt)
a,b,c and w are unknown parameters but I can estimate their aproximate values.
How can I solve the problem?
0 Comments
Accepted Answer
Star Strider
on 7 Dec 2020
You have already seen and posted a Comment to Parameter Estimation for a System of Differential Equations and that (or similar threads) are what I would direct you to.
For your application, the ‘kinetics’ objective function in that solution would be:
function Y = kinetics(theta,t)
a = theta(1);
b = theta(2);
c = theta(3);
w = theta(4);
y0 = theta(5:6);
[t,yv] = ode45(@Difeq,t,y0);
function ydot = Difeq(t,y)
ydot = zeros(2,1);
ydot(1) = y(2);
ydot(2) = -a*y(2) - b*y(1) + c*cos(w*t);
end
Y = yv;
end
Note that here the code will estimate the intial conditions as well, so ‘theta0’ must be a 6-element vector.
I obviously cannot test this, so I am posting it as UNTESTED CODE. It should work, although it may require a bit of editing.
6 Comments
Star Strider
on 9 Dec 2020
My pleasure!
I discovered that the columns of ‘y’ are incorrect, and should be reversed, the correct orientation being:
y=[v p];
since the derivatrive is the first column of ‘Y’ and its integral is the second column. (I was too tired yesterday to detect that error in your code.)
Make that change, and the fit is excellent:
Rate Constants:
Theta(1) = 0.04702
Theta(2) = 9.99643
Theta(3) = 20.76383
Theta(4) = 1.99939
Theta(5) = 3.17972
Theta(6) = 0.94858
Theta(7) = 1.39551
The fitness value (norm of the residuals) for this run was typical at 13.6113.

I plotted the two variables separately, since it is difficult to see them when all are plotted together.
Star Strider
on 9 Dec 2020
As always, my pleasure!
I typically let the optimisation function calculate everything, in order not to constrain it beyond any obvious limits (for example constraining ‘w’ and ‘p’ to
here).
More Answers (0)
See Also
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!