mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-05 17:05:34 +00:00
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:
24
samples/Matlab/RK4.m
Normal file
24
samples/Matlab/RK4.m
Normal 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
|
||||
Reference in New Issue
Block a user