In: Computer Science
Solve using the same approach as the solution using Matlab for this differential equation
d^2y/dt^2 + 6dy/dt + 9y = cos(t)
has initial conditions y(0)=1 y'(0)=2, Find Y(s) and without finding y(t),
determine what function of time will appear in the solution
%}
clear, clc
syms Y s t real
rhs = laplace(cos(t),t,s)
eqn1 = s^2*Y - s*2 - 1 + 6*s*Y -1 + 9*Y ==rhs
myanss = solve(eqn1,Y)
mypart = partfrac(myanss,'FactorMode','real')
%{
 
mypart =
 
(0.08*s + 0.06)/(s^2 + 1.0) + 1.92/(s + 3.0) - 4.3/(s + 3.0)^2
first term yields
exp(-b*t)*cos(w*t)
2nd term yields exp(-3*t)
3rd term yields t*exp(-3*t)
check
%}
myanst = (ilaplace(mypart,s,t))
%{
 
myanst =
 
exp(-t*1.0i)*(0.04 + 0.03i) + exp(t*1.0i)*(0.04 - 0.03i) + 1.92*exp(-3.0*t) - 4.3*t*exp(-3.0*t)
%}
T = [0, 20]
fplot(myanst,T)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
The equation was wrong. I corrected. L{y''(t)}=s^2*y(s)-s*y(0)-y'(0)
clc
clear all
close all
syms Y s t real
rhs = laplace(cos(t),t,s)
eqn1 = s^2*Y - s*1 - 2 + 6*s*Y -6 + 9*Y
==rhs
myanss = solve(eqn1,Y)
mypart = partfrac(myanss,'FactorMode','real')
%{
mypart =
(0.08*s + 0.06)/(s^2 + 1.0) + 1.92/(s + 3.0) - 4.3/(s +
3.0)^2
first term yields
exp(-b*t)*cos(w*t)
2nd term yields exp(-3*t)
3rd term yields t*exp(-3*t)
check
%}
myanst = (ilaplace(mypart,s,t))
%{
myanst =
exp(-t*1.0i)*(0.04 + 0.03i) + exp(t*1.0i)*(0.04 - 0.03i) +
1.92*exp(-3.0*t) - 4.3*t*exp(-3.0*t)
%}
T = [0, 20]
fplot(myanst,T)

Kindly revert for any queries
Thanks.