function z=orbit10b(inter,ic,n,p)
h=(inter(2)-inter(1))/n;
x0=ic(1);vx0=ic(2);y0=ic(3);vy0=ic(4);
x1=ic(5);vx1=ic(6);y1=ic(7);vy1=ic(8);
y(1,:)=[x0 vx0 y0 vy0 x1 vx1 y1 vy1];t(1)=inter(1);
set(gca,'XLim',[-5 5],'YLim',[-5 5],...
'XTick',[-5 0 5],'YTick',[-5 0 5]);
sun=animatedline('color','y','Marker','.','markersize',50);
addpoints(sun,0,0)
head=animatedline('color','r','Marker','.','markersize',35);
tail=animatedline('color','b','LineStyle','-');
head1=animatedline('color','r','Marker','.','markersize',35);
tail1=animatedline('color','b','LineStyle','-');
v=VideoWriter('Orbit_10b_video.mp4','MPEG-4');open(v)
for k=1:n/p
for i=1:p
t(i+1)=t(i)+h;
y(i+1,:)=trapstep(t(i),y(i,:),h);
end
y(1,:)=y(p+1,:);t(1)=t(p+1);
clearpoints(head);addpoints(head,y(1,1),y(1,3))
addpoints(tail,y(1,1),y(1,3))
drawnow;
clearpoints(head1);addpoints(head1,y(1,5),y(1,7))
addpoints(tail1,y(1,5),y(1,7))
drawnow;
frame=getframe;writeVideo(v,frame);
end
close(v)
function y=eulerstep(t,x,h)
y=x+h*ydot(t,x);
function y = trapstep(t,x,h)
z1=ydot(t,x);
g=x+h*z1;
z2=ydot(t+h,g);
y=x+h*(z1+z2)/2;
function z = ydot(t,x)
m1=0.05;g=1;mg1=m1*g;
m2=0.5;g=1;mg2=m2*g;px2=x(5);py2=x(7);
px1=x(1);py1=x(3);vx1=x(2);vy1=x(4);
vx2=x(6);vy2=x(8);
dist=sqrt((px2-px1)^2+(py2-py1)^2);
z=zeros(1,8);
z(1)=vx1;
z(2)=(mg2*(px2-px1))/(dist^3);
z(3)=vy1;
z(4)=(mg2*(py2-py1))/(dist^3);
z(5)=vx2;
z(6)=(mg1*(px1-px2))/(dist^3);
z(7)=vy2;
z(8)=(mg1*(py1-py2))/(dist^3);
Not enough input arguments.
Error in orbit10b (line 2)
h=(inter(2)-inter(1))/n; % plot n points