### Solving ODEs using Mathematica

I have found that the documentation that comes with Mathematica is not always very helpful. At least it is not very helpful when you want to know the most common operations. One of those is solving systems of first order ordinary differential equations (odes) with initial conditions. I don’t know why but I always spend a little time reading the docs to figure out how to do this when I need this functionality. To help me and perhaps others, I give the Mathematica recipe here.

Here are two examples of how to solve a single ode and a simple system of two odes. The function we will use is **DSolve[]**. This function takes three arguments:

DSolve[{odes, initial conditions}, {variable names}, independent variable]

Note the curly brackets, they must be present. For example to solve the single ode with initial condition, y(0) = 1

we need to input the following Mathematica command:

DSolve[{y'[t] == y[t] (k1 – k2) – k2, y[0] == 1}, y[t], t]

Note that the dependent variable is denoted by y[t]. The derivative of the dependent variable is denoted by y'[t]. Also note how the initial condition is entered, y[0] == 1. Don’t forget to use == instead of = in the syntax. The solution yields:

To solve a set of first order differential equations with initial equations, for example the two equations:

with initial conditions and we write the following Mathematica code where we enter the multiple equations inside the curly brackets separated by commas. Also note that because there is more than one dependent variable, we must also put these in curly brackets.

DSolve[{A'[t] == vo - k1 A[t], B'[t] == k1 A[t] - k2 B[t], A[0] == 0, B[0] == 0}, {A[t], B[t]}, t]

This will yield:

That was a great help. Thanks so much!!

Its not so much hard but for some reason I always forget the syntax, particularly setting the initial conditions. Never tried it in Matlab, I presume you mean the Matlab symbolic toolbox. I’ll take you word for it and give it miss….

If you really think solving ODE’s in Mathematica is hard or little confusing, then try to do the same in Matlab. Then you will know what hard is.

You’re absolutely right, too much LateX is my head….now fixed.

Many thanks

H

“we need to input the following Mathematica command:

DSolve[{y'[t] == y[t] (k1 – k_2) – k_2, y[0] == 1}, y[t], t]”

Those two “_” are incorrect and will deeply confuse someone trying to follow your directions.