Solving 2nd order ODE with ODE45
7 ビュー (過去 30 日間)
古いコメントを表示
Getting errors when trying to solve the following ODEs
I was following this method https://au.mathworks.com/help/symbolic/solve-differential-equation-numerically-1.html
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);
0 件のコメント
採用された回答
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!