Added matlab code samples.

All of these code samples currently are mis-identified in my repositories. I'm
donating them to the cause.
This commit is contained in:
Michele Mastropietro
2013-02-22 10:57:51 +01:00
parent b45c4f5379
commit c85255c5af
14 changed files with 803 additions and 0 deletions

24
samples/Matlab/RK4.m Normal file
View File

@@ -0,0 +1,24 @@
function x = RK4( fun, tspan, ci, mu )
%RK4 4th-order Runge Kutta integrator
% Detailed explanation goes here
h=1e-5;
t=tspan(1);
T=tspan(length(tspan));
dim=length(ci);
%x=zeros(l,dim);
x(:,1)=ci;
i=1;
while t<T
k1=fun(t,x(:,i),mu);
k2=fun(t+h/2,x(:,i)+k1*h/2,mu);
k3=fun(t+h/2,x(:,i)+k2*h/2,mu);
k4=fun(t+h,x(:,i)+h*k3,mu);
x(:,i+1)=x(:,i)+(h/6*(k1+2*k2+2*k3+k4));
t=t+h;
i=i+1;
end
x=x';
% function events(x)
% dist=
% return
end