Session 4.2 Defining and solving Differential Equations Part a One ODE
> 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);
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
> 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.
> 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:
> assign(s);x:=unapply(x(t),t); This creates a function called x that produces the solution to our ODE.
> x(t);x(0);