ch4_2a.mw


Session 4.2 Defining and solving Differential Equations Part a One ODE

The functions: dsolve, assign and unapply

> restart;

We want to solve the simple equation:

dx/dt + 2x = sin(t)

IC : x(0) = 1

Let us try the simplest way first using the diff command and trying to make our definition look just like the equation as we wrote it.:

> de:=diff(x,t)+2*x=sin(t);

de := 2*x = sin(t)

Maple did not define an ODE because it does not know that x is a function of t.

Therefore, let's add that :

> de:=diff(x(t),t)+2*x(t)=sin(t);

Note that x is now a function of t

de := diff(x(t), t)+2*x(t) = sin(t)

> ic:=x(0)=1;

ic := x(0) = 1

Note that in both the differential equation and initial condition, the set equal symbol (:=) is used for defining the variable.  The equal symbol (=) is used alone to mean equality in the expression.  Keep these symbols in mind when creating your own expressions.

 

Let's use dsolve to find x(t)

> s:=dsolve({de,ic},x(t));We will usually set the result returned by dsolve as s.

Note the variables de and ic are enclosed in braces.

s := x(t) = -1/5*cos(t)+2/5*sin(t)+6/5*exp(-2*t)

> x(t);  This has not been defined however.  In order to make our solution useful as a function, we need to use two more steps.  I will show them in the same line since they are so commonly used:

x(t)

> assign(s);x:=unapply(x(t),t);This creates a function called x that produces the solution to our ODE.

x := proc (t) options operator, arrow; -1/5*cos(t)+2/5*sin(t)+6/5*exp(-2*t) end proc

> x(t);x(0);

-1/5*cos(t)+2/5*sin(t)+6/5*exp(-2*t)

1

>