Justin`s Guide to MATLAB - Part 4 1. Solving Second Order Linear

advertisement
Justin’s Guide to MATLAB - Part 4
1. Solving Second Order Linear Differential Equations
MATLAB can solve some basic second order differential equations that we’ve tackled, like y ′′ − 2y ′ −
15y = 0. We use D2y to represent y ′′ :
>> dsolve(’D2y-2*Dy-15*y=0’)
This has real roots of the characteristic equation but MATLAB can tackle complex roots, like with
y ′′ − y ′ + 3y = 0:
>> dsolve(’D2y-Dy+3*y=0’)
and repeated roots and with initial values, as with y ′′ − 6y ′ + 9y = 0, y(0) = 2, y ′ (0) = 3:
>> dsolve(’D2y-6*Dy+9*y=0’,’y(0)=2’,’Dy(0)=3’)
It can also handle some nonhomogeneous equations for which we might use the Method of Undetermined
Coefficients, like y ′′ + y = 3 sin(2t) + t cos(2t):
>> dsolve(’D2y+y=3*sin(2*t)+t*cos(2*t)’)
Or for which we might use Variation of Parameters, like y ′′ + y = tan t:
>> dsolve(’D2y+y=tan(t)’)
It can also manage some DEs with nonconstant coefficients, such as t2 y ′′ − 2y = 3t2 − 1:
>> dsolve(’t^2*D2y-2*y=3*t^2-1’)
2. Helping with Steps
Of course this is very helpful but if we’re trying to really understand the steps then it might be better
for MATLAB to help us with the steps of a problem rather than explicitly solving the problem for us.
In this vein, consider something like y ′′ − 2y ′ − 15y = t2 e2t . The Method of Undetermined Coefficients
suggests that something like y = (At2 + Bt + c)e2t ought to work. In light of this we can find the first
and second derivatives:
>> syms t
>> myy=’(A*t^2+B*t+C)*exp(2*t)’
>> mydy=diff(myy,t)
>> myddy=diff(myy,t,2)
We then substitute them in to the differential equation and simplify:
>> simple(subs(’D2y-2*Dy-15*y=t^2*exp(2*t)’,{’y’,’Dy’,’D2y’}, {myy,mydy,myddy}))
The result in this case is:
2*A+4*A*t+2*B-15*A*t^2-15*B*t-15*C)*exp(2*t) = t^2*exp(2*t)
And we cancel the e2t and equate coefficients and solve:
>> [A,B,C]=solve(’2*A+2*B-15*C=0,4*A-15*B=0,-15*A=1’,’A,B,C’)
Which gives us A = −1/15, B = −4/225 and C = −38/3375.
Exercises
1. For each of the following homogeneous equations, first find the general solution for the DE and then
solve the IVP.
(a) y ′′ + 9y ′ + 18y = 0, y(0) = 1, y ′ (0) = −1.
(b) y ′′ − 10y ′ + 25y = 0, y(0) = 0, y ′ (0) = 7.
(c) y ′′ − y ′ + 3y = 0, y(0) = 3, y ′ (0) = −2.
2. Do the same as in (1) but for these nonhomogeneous equations.
(a) y ′′ + 9y ′ + 18y = t3 e−5t + sin(t), y(0) = 0, y ′ (0) = 1.
(b) y ′′ + 25y = csc t, y π3 = 0, y ′ π3 = 1.
3. Consider the spring modeled by the initial value problem u′′ + au′ + 20u = 0, u(0) = 5, u′ (0) = 0.
(a) Determine the value a = a0 for which the motion is critically damped.
(b) Solve the IVP for the value a = 0 using dsolve. Plot it using fplot. This command is more
flexible than ezplot because we can specify both the t and y limits. We’ll do this as follows:
>> boing=dsolve(’D2u+0*Du+20*u=0’,’u(0)=5’,’Du(0)=0’)
>> fplot(char(boing),[0,10,-6,6])
(c) Turn
>> hold on
so your figure remains and then successively solve and plot the IVP with values a = 1, 5, a0 , 15.
This is as simple as reissuing the dsolve and fplot commands with the correct values inserted.
Download