Solving 2nd order ODE with ODE45
Show older comments
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);
Accepted Answer
More Answers (1)
Torsten
on 8 May 2019
2 votes
M = matlabFunction(V,'vars', {'t','Y'})
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!