I am tring to apply 2nd newton law to many points, where m,r,v,f is a n-by-1, n-by-3, n-by-3, n-by-3, n-by-3, matrixes for mass, position,velocity, and force for n points. The 3 columns are the x,y,z components for those values.
options = odeset('Vectorized','on');
y0=[r,v];
[t,YSol]=ode45(@(t,y) MotionODE(t,y,m,f),[0,dt],y0,options);
r=YSol(t==dt,1:3)';
v=YSol(t==dt,4:5)';
function d2rdt2= MotionODE(t,Y,m,f)
r=Y(:,1:3);
v=Y(:,4:5);
drdt=v;
dvdt=f./m;
d2rdt2=[drdt,dvdt];
end
However I got an error: "Index in position 2 exceeds array bounds (must not exceed 1).". Is the option "vectorized" designed for what I think it is for? How do I get this run correctly (other than a for loop)?