ASCIIMath input, SVGMath output example

What is ASCIIMath?

This page is a demo of math written using ASCIIMath, which provides a very easy method for entering math, similar to a graphic calculator. It saves a lot of the hassle of LaTeX. For example, a fraction is as easy as `a = b/c`.

You don't see any ASCIIMath in the page source because it has already been processed on the server before being delivered here.

What is SVGMath?

The math output on this page consists of SVGs embedded in image tags. It results in much faster rendering than either MathJax or KaTeX, while retaining the same attractive presentation and some of the accessibility.

See the SVGMath demo and SVGMath overview, which has comparison statistics between SVGMath, MathJax and KaTeX.

The content on this page is from my old IntMath site.

[ASCIIMath input, SVGMath output demo starts]

Runge-Kutta (RK4) numerical solution for Differential Equations

The Runge-Kutta Method produces a better result than Euler's Method in fewer steps.

Runge-Kutta Method Order 4 Formula

math expression: y left parenthesis x plus h right parenthesis math expression: equals y left parenthesis x right parenthesis plus math expression: one sixth left parenthesis upper F 1 plus 2 upper F 2 plus 2 upper F 3 plus upper F 4 right parenthesis

where

math expression: upper F 1 equals h f left parenthesis x comma y right parenthesis

math expression: upper F 2 equals h f left parenthesis x plus StartFraction h Over 2 EndFraction comma y plus StartFraction upper F 1 Over 2 EndFraction right parenthesis

math expression: upper F 3 equals h f left parenthesis x plus StartFraction h Over 2 EndFraction comma y plus StartFraction upper F 2 Over 2 EndFraction right parenthesis

math expression: upper F 4 equals h f left parenthesis x plus h comma y plus upper F 3 right parenthesis

Runge-Kutta Method of Order 2

We begin with two function evaluations of the form:

math expression: upper F 1 equals h f left parenthesis x comma y right parenthesis

math expression: upper F 2 equals h f left parenthesis x plus alpha h comma y plus beta upper F 1 right parenthesis

The math expression: alpha and math expression: beta are unknown quantities. The idea was to take a linear combination of the math expression: upper F 1 and math expression: upper F 2 terms to obtain an approximation for the y value at math expression: x equals x 0 plus h, and to find appropriate values of math expression: alpha and math expression: beta.

By comparing the values obtains using Taylor's Series method and the above terms (I will spare you the details here), they obtained the following, which is Runge-Kutta Method of Order 2:

math expression: y left parenthesis x plus h right parenthesis equals y left parenthesis x right parenthesis plus one half left parenthesis upper F 1 plus upper F 2 right parenthesis

where

math expression: upper F 1 equals h f left parenthesis x comma y right parenthesis

math expression: upper F 2 equals h f left parenthesis x plus h comma y plus upper F 1 right parenthesis

Runge-Kutta Method of Order 3

As usual in this work, the more terms we take, the better the solution. In practice, the Order 2 solution is rarely used because it is not very accurate.

A better result is given by the Order 3 method:

math expression: y left parenthesis x plus h right parenthesis equals math expression: y left parenthesis x right parenthesis plus one ninth left parenthesis 2 upper F 1 plus 3 upper F 2 plus 4 upper F 3 right parenthesis

where

math expression: upper F 1 equals h f left parenthesis x comma y right parenthesis

math expression: upper F 2 equals h f left parenthesis x plus StartFraction h Over 2 EndFraction comma y plus StartFraction upper F 1 Over 2 EndFraction right parenthesis

math expression: upper F 3 equals h f left parenthesis x plus StartFraction 3 h Over 4 EndFraction comma y plus StartFraction 3 upper F 2 Over 4 EndFraction right parenthesis

This was obtained in a similar way to the earlier formula, by comparing Taylor's Series results.

The most commonly used Runge-Kutta formula in use is the Order 4 formula (RK4), as it gives the best trade-off between computational requirements and accuracy.

Let's look at an example to see how it works.

Example

Use Runge-Kutta Method of Order 4 to solve the following, using a step size of math expression: h equals 0.1 for math expression: 0 less than or equals x less than or equals 1.

math expression: StartFraction d y Over d x EndFraction equals StartFraction 5 x squared minus y Over e Superscript x plus y Baseline EndFraction

math expression: y left parenthesis 0 right parenthesis equals 1

Step 1

Note: The following looks tedious, and it is. We'll use a computer (not calculator) to do most of the work for us. The following is here so you can see how the formula is applied.

We start with math expression: x equals 0 and math expression: y equals 1. We'll find the F values first:

math expression: upper F 1 equals h f left parenthesis x comma y right parenthesis math expression: equals 0.1 StartFraction 5 left parenthesis 0 right parenthesis squared minus 1 Over e Superscript 0 plus 1 Baseline EndFraction math expression: equals negative 0.03678794411

For math expression: upper F 2, we need to know:

math expression: x plus StartFraction h Over 2 EndFraction equals 0 plus StartFraction 0.1 Over 2 EndFraction equals 0.05, and

math expression: y plus StartFraction upper F 1 Over 2 EndFraction equals 1 plus StartFraction negative 0.03678794411 Over 2 EndFraction math expression: equals 0.98160602794

We substitute these into the math expression: upper F 2 expression:

math expression: upper F 2 equals h f left parenthesis x plus StartFraction h Over 2 EndFraction comma y plus StartFraction upper F 1 Over 2 EndFraction right parenthesis math expression: equals 0.1 left parenthesis StartFraction 5 left parenthesis 0.05 right parenthesis squared minus 0.98160602794 Over e Superscript 0.05 plus 0.98160602794 Baseline EndFraction right parenthesis math expression: equals negative 0.03454223937

For math expression: upper F 3, we need to know:

math expression: y plus StartFraction upper F 2 Over 2 EndFraction equals 1 plus StartFraction negative 0.03454223937 Over 2 EndFraction math expression: equals 0.98272888031

So

math expression: upper F 3 equals h f left parenthesis x plus StartFraction h Over 2 EndFraction comma y plus StartFraction upper F 2 Over 2 EndFraction right parenthesis math expression: equals 0.1 left parenthesis StartFraction 5 left parenthesis 0.05 right parenthesis squared minus 0.98272888031 Over e Superscript 0.05 plus 0.98272888031 Baseline EndFraction right parenthesis math expression: equals negative 0.03454345267

For math expression: upper F 4, we need to know:

math expression: y plus upper F 3 math expression: equals 1 minus 0.03454345267 math expression: equals 0.96545654732

So

math expression: upper F 4 equals h f left parenthesis x plus h comma y plus upper F 3 right parenthesis math expression: equals 0.1 left parenthesis StartFraction 5 left parenthesis 0.1 right parenthesis squared minus 0.96545654732 Over e Superscript 0.1 plus 0.96545654732 Baseline EndFraction right parenthesis math expression: equals negative 0.03154393258

Step 2

Next, we take those 4 values and substitute them into the Runge-Kutta RK4 formula:

math expression: y left parenthesis x plus h right parenthesis equals y left parenthesis x right parenthesis plus math expression: one sixth left parenthesis upper F 1 plus 2 upper F 2 plus 2 upper F 3 plus upper F 4 right parenthesis

math expression: equals 1 plus one sixth left parenthesis negative 0.03678794411 math expression: minus 2 times 0.03454223937 math expression: minus 2 times 0.03454345267 math expression: minus 0.03154393258 right parenthesis

math expression: equals 0.9655827899

Using this new y-value, we would start again, finding the new math expression: upper F 1, math expression: upper F 2, math expression: upper F 3 and math expression: upper F 4, and substitute into the Runge-Kutta formula.

[ASCIIMath input, SVGMath output demo ends]

See also

See the SVGMath demo which has comparisons with MathJax and KaTeX processing, and SVGMath overview, which has comparison statistics between SVGMath, MathJax and KaTeX.