필터 지우기
필터 지우기

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

조회 수: 2 (최근 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
Matt J
Matt J 2022년 8월 11일
mampl are the Amplitudes of for different Frequencies (frqSet).
Different frequencies ?

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

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