Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Sample simple Runge-Kutta solution in Mathcad, Example 1.9 in Heinsohn, Cimbala book J. M. Cimbala.

Latest update: September 2005 Consider an ODE for y(t) in standard form, i.e. dy/dt = B - Ay. In general, A and B can be funtions of time. A( t) 3.82 B( t) 10.0

The starting time is tstart and the ending time is tend. npts is the number of time increments from these extremes. tstart 0 tend 0.54 npts 50

The value of y must be specified at the initial condition (starting time). y 7.60 The derivative of the function will be called D, where D is a function of both time and y. D( t y ) B( t) A( t) y Now Mathcad can march in time using the Runge-Kutta function, Rkadapt. Output Rkadapt ( y tstart tend npts D) Note: Mathcad's output is an array. The first column (column 0) is the marching variable, which here is time. The second column (column 1) is the dependent variable, in this case y. More columns would be added if the varaible array had more than one variable.

0 0 1 2 3 4 5 6 0 0.011 0.022 0.032 0.043 0.054 0.065 0.076 0.086 0.097 0.108 0.119 0.13 0.14 0.151 0.162

1 7.6 7.399 7.205 7.02 6.671 6.508 6.35 6.199 6.055 5.916 5.782 5.655 5.532 5.414 ... variable, y 6.842

6 1 Output 5

Output 7
8 9 10 11 12 13 14 15

0.2 0 Output time, t

0.4

0.6

At the ending time, tend, one can calculate y as follows. Note: Use the "[" key to make a subscript. y_tend Output
npts 1

y_tend 3.251

You might also like