Ode system solution with unknown constant

조회 수: 5 (최근 30일)
ana ramirez de las heras
ana ramirez de las heras 2020년 12월 7일
댓글: Star Strider 2020년 12월 9일
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?

채택된 답변

Star Strider
Star Strider 2020년 12월 7일
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
Star Strider
Star Strider 2020년 12월 9일
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
Star Strider 2020년 12월 9일
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).

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

추가 답변 (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