


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Math 308
This Maple session contains examples that show how to solve certain second order constant coefficient differential equations in Maple. Also, at the end, the "subs" command is introduced.
First, we solve the homogeneous equation y'' + 2y' + 5y = 0. We'll call the equation "eq1": > eq1 := diff(y(t),t,t) + 2diff(y(t),t) + 5y(t) = 0;**
eq1 := + + =
t^2
y( ) t 2
t y( )^ t^^5 y( )^ t^^0 We use the "dsolve" command to solve the differential equation. In its basic form, this command takes two arguments. The first is the differential equation, and the second is the function to be found. We'll use the "rhs" command to save the actual solution in the variable "sol1": > sol1 := rhs(dsolve(eq1,y(t)));
sol1 := _C1 e + ( − t ) sin 2 ( t ) _C2 e ( − t ) cos 2 ( t ) The two expressions _C1 and _C2 are Maple's "arbitrary constants".
That was easy enough. How do we specify initial conditions? Consider the initial value problem y'' + 2y' + 5y = 0, y(0)=3, y'(0)=-5. We use the "dsolve" command again, but we now make a list of the equation and the initial conditions. The first initial condition, y(0) =3, is written in Maple just as it is here. However, to enter the initial value of y', we can not simply write y'(0)=-5. The single quote ' has a special meaning in Maple, and it is not a derivative. Instead, we use the "D" operator. The operator "D" is another way to specify the derivative of a function. The derivative y'(t) can be expressed in Maple as D(y)(t). "D(y)" means "the derivative of y", so "D(y)(t)" means "the derivative of y evaluated at t". To specify the initial condition y'(0)=-5, we use "D(y)(0)=-5". We use this in the following command: > sol1ivp := rhs(dsolve({eq1,y(0)=3,D(y)(0)=-5},y(t)));
sol1ivp :=− e + ( − t ) sin 2 ( t ) 3 e ( − t ) cos 2 ( t ) Note that the first argument to "dsolve" is a list of three elements: {eq1,y(0)=3,D(y)(0)=-5}. This is the initial value problem to be solved. As before, the second argument is just y(t), the function to be found. Plot the solution. > plot(sol1ivp,t=-1..6,labels=["t","y"]);
Now let's try a nonhomogeneous example: y'' + 2y' + 5y = 3sin(2t). > eq2 := diff(y(t),t,t) + 2diff(y(t),t) + 5y(t) = 3sin(2t);**
eq2 := + + =
t^2
y( ) t 2
t y( ) t 5 y( ) t 3 sin 2( t )
Use "dsolve" to find the general solution. > sol2 := dsolve(eq2,y(t));
sol2 :=y( ) t = e + + − ( − t ) sin 2 ( t ) _C2 e ( − t ) cos 2 ( t ) _C
sin 2( t )
cos 2( t )
Now solve an initial value problem. We'll use the same initial conditions as before. > sol2ivp := rhs(dsolve({eq2,y(0)=3,D(y)(0)=-5},y(t)));
sol2ivp :=− + + −
e (^ − t )sin 2 ( t )
e (^ − t )cos 2 ( t )
sin 2( t )
cos 2( t )
> plot(sol2ivp,t=0..15);
sol4 := _C1 e (^ (^ −^2 + −^ k^ +^4 ) t )+ _C2 e (^ (^ −^2 − −^ k^ +^4 ) t ) Note, however, that Maple has only given the solution that we expect when k < 4. If k=4, then Maple's solution is not complete (it is missing the term t*exp(-2t)), and if k < 4, Maple's answer will become complex-valued (and we want real-valued solutions). If Maple knows the numerical value of k, it will give the correct form of the answer. To show this, I'll first introduce a useful function called "subs".
The "subs" command (short for "substitute") allows you to replace variables in an expression with other variables or values. For example: > p := x^3+4x^2-xy + y^2 +1;**
p := x^3 + 4 x^2 − x y + y^2 + 1 To find the value of this expression when x=3, we can use the following command: > subs(x=3,p);
64 − 3 y + y^2 The last argument of "subs" is the expression in which to make the substitutions. The other arguments have the form variable=value. More than one subsitution can be given in the command: > subs(x=3,y=5,p); 74 Now we'll use the "subs" command to create copies of eq4 with several different numerical values of k. > eq4a := subs(k=1,eq4);
eq4a := + + =
t^2
y( ) t 4
t y( )^ t^ y( )^ t^^0 > dsolve(eq4a,y(t));
y( ) t = _C1 e + ( ( − 2 + 3 ) t ) _C2 e ( −( 2 + 3 ) t )
> eq4b := subs(k=4,eq4);
eq4b := + + =
t^2
y( ) t 4
t y( ) t 4 y( ) t 0
> dsolve(eq4b,y(t));
y( ) t = _C1 e + ( − 2 t ) _C2 e ( − 2 t ) t Notice that Maple gave the correct answer here. > eq4c := subs(k=8,eq4);
eq4c := + + =
t^2
y( ) t 4
t y( ) t 8 y( ) t 0
> dsolve(eq4c,y(t));
y( ) t = _C1 e + ( − 2 t ) sin 2 ( t ) _C2 e ( − 2 t ) cos 2 ( t ) And here it gave the correct, real-valued solution.