problem ode45 system of differential equation
Show older comments
hi, i have to solve this problem about the orbit of the halley comet, but when i run the code i get unphysical values.
up on this text , i uploaded the two equation to solve, and C= -M*G.
i splitted the two equation of the acceleration in four eqs.
anyone can tell me what's the problem with the code?
CODE:
tSpan=[0 2.33e9]
y0=[8.6e7 0 0 55.1]
[tSol,ySol]=ode45(@cometa,tSpan,y0)
plot(tSol,ySol(:,1));
hold on
plot(tSol,ySol(:,2));
plot(tSol,ySol(:,3));
plot(tSol,ySol(:,4));
hold off
legend('x','vx','y','vy')
function dYdt=cometa(t,Y)
C=-1.33e20;
% x vx y vy % x=Y(1), vx=Y(2), y=Y(3), vy=Y(4)
r=sqrt((Y(1).^2+Y(3).^2));
dxdt=Y(2);
dvxdt=C.*Y(1)./r.^(3);
dydt=Y(4)
dvydt=C.*Y(3)./r.^(3);
dYdt=[dxdt;dvxdt;dydt;dvydt];
end
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!