ddhr.org
Code - rungekutta Thursday, Jan 22, 2009 10:55 am

This is a Matlab function that uses the Runge-Kutta method of numerical approximation to predict values of differential equations.  I wrote it for a point mass simulation, which is a simplified model of the motion of a spherical object. 

function output = rungekutta(x,dt,f)
%RUNGEKUTTA   Numerical integration (prediction).
%   RUNGEKUTTA(X,DT,F) uses a fourth-order Runge-Kutta
%   prediction routine to determine the next value of a
%   function based on the current value.  X can be any
%   number or array of numbers, DT is the time step for
%   integration, and F is the name of the function to
%   integrate (with single quotes).
%
%   Example:
%      position2 = rungekutta(position1,0.01,'equations')

k1 = dt*feval(f,x);
k2 = dt*feval(f,x+k1./2);
k3 = dt*feval(f,x+k2./2);
k4 = dt*feval(f,x+k3);
   
output = x+(k1+2.*k2+2.*k3+k4)./6;

Download

Linked:  Code

Hello
Hi, my name is Dave Hosier, and this website is where I write my unfounded opinions on trivial matters. Feel free to look around, but please refrain from reading anything.

about | contact | feed

Comments (feed)
Rich on Old age pains: Injuries from sleeping: yes, me...
Dave on Wedding investment: Well obviously stay away from...
Rus on Wedding investment: Can you advise us on...
Someone who is not young but not old on Old age pains: Regarding Paragraph 1 Sentence 2,...
Bobby on Blackberry vs. black raspberry: I grew up in Olney,...
Richi near Frankfurt/M. on WinXP .mov thumbnails: Thanks Dude, that solved my...
saphrenne on Strummit From The Summit: I love this song so...
Rosalyne on Blackberry vs. black raspberry: I grew up eating BlackCaps...
BONNIE on Glitter cards: thats awsome... i laugh out...
Christy on WinXP .mov thumbnails: was skeptical at first... Windows...