Solving 2nd order ODE with ODE45

조회 수: 3 (최근 30일)
Ash
Ash 2019년 5월 8일
댓글: Bjorn Gustavsson 2019년 5월 8일
Getting errors when trying to solve the following ODEs
Capture.JPG
Capture1.JPG
Capture2.JPG
My code
syms y1(t)
syms y2(t)
u=0.012277471;
D1=(((y1+u)^2)+(y2^2))^(3/2);
D2=(((y1-(1-u))^2)+(y2^2))^(3/2);
[V]=odeToVectorField(diff(y1, 2) ==y1+2*diff(y2)-((1-u)*(y1+u)/D1)-u*((y1-(1-u))/D2),...
diff(y2, 2)==y2-2*diff(y2)-(1-u)*(y2/D1)-u*(y2/D2)); %converting 2nd order differential equations to 1st order
M = matlabFunction(V); %Converting symbolic expression to function handle
tspan=[0 17.065216560];
% y1(0) y1'(0) y2(0) y2'(0)
yo=[ 0.994, 0, 0, -2.001585106];
sol = ode45(M,tspan,yo)
My outputs
Error using symengine>@(Y)[Y(2);1.0./(Y(1).^2+(Y(3)+1.2277471e-2).^2).^(3.0./2.0).*Y(1).*(-9.87722529e-1)+Y(1)-Y(2).*2.0-1.0./((Y(3)-9.87722529e-1).^2+Y(1).^2).^(3.0./2.0).*Y(1).*1.2277471e-2;Y(4);-1.0./(Y(1).^2+(Y(3)+1.2277471e-2).^2).^(3.0./2.0).*(Y(3).*9.87722529e-1+1.212673470584416e-2)+Y(2).*2.0+Y(3)-1.0./((Y(3)-9.87722529e-1).^2+Y(1).^2).^(3.0./2.0).*(Y(3)-9.87722529e-1).*1.2277471e-2]
Too many input arguments.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 5월 8일
편집: Torsten 2019년 5월 8일
Dont bother with the hassle to go through symbolic-variables and ode2vectorfield when transforming your 2 clean 2nd-order ODEs. Convert them by hand!
function dy12dt = myODE(t,y,mu)
y1 = y(1);
y2 = y(2);
dy1dt = y(3);
dy2dt = y(4);
D1 = ((y1+mu)^2 + y2^2)^(3/2);
d2y1dt2 = y1 + 2*dy2dt + (1-mu)*(y1+mu)/D1;
% ...and so on for d2y2dt2
dy12dt = [dy1dt;dy2dt;d2y1dt2;d2y2dt2]
end
Then you have a system of four coupled first-order ODEs to solve with ode45 with time-span and initial conditions of your choice...
HTH
  댓글 수: 1
Bjorn Gustavsson
Bjorn Gustavsson 2019년 5월 8일
@Torsten: What did I mess up this time?

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

추가 답변 (1개)

Torsten
Torsten 2019년 5월 8일
M = matlabFunction(V,'vars', {'t','Y'})

카테고리

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