How can i fit ODE parameters to given frequency and amplitude data pairs with "lsqcurvefit"?

4 次查看(过去 30 天)
Hello there,
i have a problem to implementing a ODE to the lsqcurvefit function. My ODE: a simple spring-damper-mass oszillator. And i have amplitude (mampl) and frequency (frqSet) data to which the parameters should be adjusted.
I have written this so far but i am not getting anywhere:
xd=frqSet;
yd=mampl;
x0=[1e-4 1e+0 1e-10 1e-9];
opts = optimoptions('lsqcurvefit','MaxFunctionEvaluations',10000,'FunctionTolerance',1e-8,'StepTolerance',1e-8,'MaxIterations',10000,'OptimalityTolerance',1e-8);
lx = [1e-4 1e+0 1e-10 1e-9];
ux = [1e-2 1e+2 1e-7 1e-6];
x = lsqcurvefit(@fitfun,x0,xd,yd,lx,ux,opts);
function fitfun(x,xd)
ts = [2*pi/1.001e+5 2*pi/1.002e+5];
u0 = 1e-7;
[ta,ua] = ode45(@(u,t) f(u,t),ts,u0);
function dudt= f(u,t)
dudt = x(4).*sin(xd.*t)./(x(2))-2.*x(1).*sqrt(x(2)./x(3)).*x(3).*u(1)./x(2)-u(2).*x(3)./x(2);
end
end
Thanks for help in advance.
  5 个评论

请先登录,再进行评论。

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2022-8-10
There are two issues you will have to solve. The first is to convert your second order ODE to two coupled first-order ODEs. The second is to wrap everything into an "error-function" for the fit to your data such that you can optimise the parameters.
The first step will be to re-write the equation-of-motion function to something like this:
function dudtdu2dt2= f(u,t)
% First derivative/Velocity
dudt = u(2);
% Second derivative/acceleration note the changes of indices v v
du2dt2 = x(4).*sin(xd.*t)./(x(2))-2.*x(1).*sqrt(x(2)./x(3)).*m.*u(2)./x(2)-u(1).*x(3)./x(2);
dudtdu2dt2 = [dudt;du2dt2]; % Return the column vector of [v;a]
end
For the second step have a look at the solution to a similar enough problem here: monod-kinetics-and-curve-fitting. The ODEs that are solved there are completely different but the technique/programming pattern is identical.
HTH
  9 个评论
Paul-Adam
Paul-Adam 2022-8-11
I don't know how to generate an symbolic equation with relation between amplitude and frequency, but do you mean by harmonic expansion the hamonic balance method? Like
Bjorn Gustavsson
Bjorn Gustavsson 2022-8-11
With harmonic expansion I mean that you can make the ansatz:
This happily ignores the onset but will give you the right long-term behaviour. The velocity and acceleration you get:
These you can then plug into your equation of motion - and notice that the complex exponentials cancels out - what remains is an algebraic equation for - the amplitude of the oscillation. You will find that it is now a complex variable, but that only means that the real and imaginary parts explain how much the oscillation is phase-shifted relative to the driving force. This equation you can solve for and calculate its absolute value for. This should be the analytical expression for the relation between the amplitude and frequency. We can do this because your equation of motion is linear, that gives us only complex exponentials that can be factored out. If you had a non-linear equation-of-motion this would not always be possible, for example if we had a term with a factor then this harmonic expansion would lead to one term with - this would couple the equations for different frequencies and be much more challenging.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by