Fitting experimental data to spring damper ODE

13 visualizzazioni (ultimi 30 giorni)
sina rafati
sina rafati il 17 Gen 2021
Risposto: Star Strider il 17 Gen 2021
Hello All,
I am trying to fit an experimental data to an ODE system. Let’s say I have a fluid system which I have found the real time force balance. I have also experimental data providing location and velocity of the fluid parcel of interest. I would like to model this as spring damper ODE.
Here is conversion of the ODE to system of 1st order ODE:
I have seen answers like Parameter Estimation for a System of Differential Equations or Fitting experimental data to an ODE model. However, none of these have non homogenous ODE (in my case having extra force term). The objective is to find k,b,m assuming I have x(t),xdot(t), and f(t).
Here is a piece of code I put together for homogenous problem. I wonder if someone can guide me how I can add the force term to the optimization problem.
global time X xi pi
time= Data.Time(locs:end); %time
X=[Data.location, Data.velocity] %Data
xi= [Data.location(1), Data.velocity(1)]'; %initial values
pi= [1 1]'; %initial parameter guess
opt = fminsearch(@(p) optim(time,X,p,xi), pi); %optimization
function dxVec = ODEFunc(p,t,xVec)
r1= xVec(2);
r2= (-(p(1)/p(3)) * xVec(1) - (p(2) * xVec(2)));
dxVec = [r1;r2];
end
function SSE = optim(time,X,p,xi)
global time X xi
f = @(t,xVec) ODEFunc(p,t,xVec);
[tm, xVecm] = ode45(f, time, xi); %prediction
err = X - xVecm;
SSE = sum(err.^2); %sum squared-error.
end

Risposte (1)

Star Strider
Star Strider il 17 Gen 2021
You have already referenced two (of the many possibilities I have posted) to estimate the parameters of your system that I would have directed you to for guidance.
First, do not use global variables! Pass the variables as e xtra parameters. See the documentation section on Passing Extra Parameters to understand how to do that.
Second, to fit position and acceletation, use both columns of ‘xVcem’ to your data. (Your data must be column vectors for that to work.) Since force is mass multiplied by acceleration, multiply acceleration by a constant mass term to calculate it. (This does not appear to be a rocket or similar simulation where mass would change as a function of time.)
Third, ‘ODEfunc’ is incorrect. The independent variable must be the first argument, and the dependent variable the second argument. See the posts you have already referenced for guidance on how to include the parameter vector.

Community Treasure Hunt

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

Start Hunting!

Translated by