필터 지우기
필터 지우기

Using ode45 for a non linear differential equation with a term in a vector form

조회 수: 1 (최근 30일)
Hello,
I want to solve the 2nd order differential equation:
d^2(xus)/dt^2 = -K/Mus*xus-Ms/Mus*d^2(xs)/dt^2
I found as = d^2(xs)/dt^2 experimentally with potentiometer so I have as a 90000x1 vector that corresponds to the acceleration at each time t and now I want to find xus in function of this same time t using ode45
The problem is that I don't know how to deal with as in ode45 and I have the error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size
of the right side is 0-by-1.
Considering that as is given the rest of my code is:
Mus=100;
Ms=10;
K=1000;
tspan=linspace(0,(size(as)-1)*0.02,size(as));
x0 = [0 0];
[t,x] = ode45(@(t,x) fun(t,x,as,Mus,Ms,K,tspan), tspan, x0);
function dx_dt = fun(t,x,as,Mus,Ms,K,tspan)
i=find(tspan==t);
a=as(i);
dx_dt(1,1) = x(2);
dx_dt(2,1) =-K/Mus*x(1)-Ms/Mus*a;
end
Thank you in advance for your help

채택된 답변

Star Strider
Star Strider 2021년 11월 24일
I do not understand the problem.
Is the objective to estimate a parameters of the differential equation from data?
The time value at each iteration is supplied to the ode45 function so there is no reason to specify it directly. If the data were collected at specific times, use that time vector for ‘tspan’ in the differential equation call. Are the values of ‘K’, ‘Ms’, and ‘Mus’ known, or are they to be estimated (as parameters) from the data?
The derivation is fairly straightforward using the Symbolic Math Toolbox —
syms D2xs K Ms Mus T t xus(t) Y
Dxus = diff(xus);
D2xus = diff(Dxus);
Eqn = D2xus == -K/Mus*xus-Ms/Mus*D2xs
Eqn(t) = 
[VF,Sbs] = odeToVectorField(Eqn)
VF = 
Sbs = 
xusfcn = matlabFunction(VF, 'Vars',{T,Y,D2xs,K,Ms,Mus})
xusfcn = function_handle with value:
@(T,Y,D2xs,K,Ms,Mus)[Y(2);-(K.*Y(1))./Mus-(D2xs.*Ms)./Mus]
It would help to upload/attach the time and vectors (as a matrix as (90000x2) matrix if the intent is to estimate parameters from it.
.
  댓글 수: 6
Star Strider
Star Strider 2021년 11월 24일
As always, my pleasure!
The order of the arguments can be changed by using the 'Vars' name-value pair in the matlabFunction call. That might make them easier to work with. (All calls to the function have to have their argument list changed to match it, if it the order is changed.)
.

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

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