# Explicit Runge-Kutta Method

Write a general purpose RK routine; here described in a matlab

context (but feel free to re-interpret into and program in any language environment)

[t_out,y_out,e_out] = rk ( ode_RHS, y_0, t_range, c, A, b1, b2 )

input parameters:

ode_RHS= function handle to right side f of the ODE y'=f(t,y)

y_0= initial value for ODE

t_range=the vector T_start:h:T_stop where h is the step size

c= the vector c in the butcher array that specifies the RK method

A= the matrix A in the butcher array that specifies the RK method

b1= vector in the butcher array that specifies primary RK method

b2= vector in the butcher array that specifies secondary RK method

output parameters:

t_out= the times where the solution was computed

y_out=the solution computed at the times t_out

e_out= the step-error estimated at the times t_out. Computed only when b2 is supplied.

Where is the step size h? You probably want to use something like

h_current_step=t_range(k) - t_range(k-1)

so that your code does not break if/when user passes in a non-uniform

t_range

,

e.g.t_range = [0 0.1 0.2 0.4 0.46 0.47 0.5 0.7 0.8 0.9 0.99 0.999 0.9999 1].

https://brainmass.com/math/discrete-math/explicit-runge-kutta-method-530081

## SOLUTION This solution is **FREE** courtesy of BrainMass!

Two scripts are uploaded:

GenRK.m is the general Runge-Kutta script requested

testGenRK.m is a script to test it with various inputs

GenRK follows the Adaptive RK prescription on web page http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods.

If anything is in the least unclear, please ask you questions via messages and I shall do my best to explain.

Â© BrainMass Inc. brainmass.com October 3, 2022, 11:20 pm ad1c9bdddf>https://brainmass.com/math/discrete-math/explicit-runge-kutta-method-530081