# Chapter 13: Linear Differential Equations¶

## Example 13.1, page no. 398¶

In :
import sympy, numpy

print "Solution to the given linear differential equation is given by: "
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**2+m-2
r = numpy.roots([2, 1, -2])
y = c1*sympy.exp(r*x)+c2*sympy.exp(r*x)
print "y = ", y

Solution to the given linear differential equation is given by:
y =  c1*exp(-1.28077640640442*x) + c2*exp(0.780776406404415*x)


## Example 13.2, page no. 399¶

In :
import sympy, numpy

print 'Solution to the given linear differntial equation is given by: '
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**2+6*m+9;
r = numpy.roots([2, 6, 9])
y =(c1+x*c2)*sympy.exp(r*x)
print "y = ", y

Solution to the given linear differntial equation is given by:
y =  (c1 + c2*x)*exp(x*(-1.5 + 1.5*I))


## Example 13.3, page no. 401¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
c3 = sympy.Symbol('c3')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**3+m*2+4*m+4;
r = numpy.roots([3, 2, 4, 4])
y = c1*sympy.exp(r.real*x)+c2*sympy.exp(r.real*x)+c3*sympy.exp(r.real*x)
print "y = ", y

Solution to the given linear differntial equation is given by:
y =  c1*exp(0.105616806777468*x) + c2*exp(0.105616806777468*x) + c3*exp(-0.877900280221601*x)


## Example 13.4, page no. 402¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
c3 = sympy.Symbol('c3')
c4 = sympy.Symbol('c4')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**4+4;
r = numpy.roots([4, 0, 0, 0, 4])
y = c1*sympy.exp(r.real*x)+c2*sympy.exp(r.real*x)+c3*sympy.exp(r.real*x)+c4*sympy.exp(r.real*x)
print "y = ", y

Solution to the given linear differntial equation is given by:
y =  c1*exp(-0.707106781186547*x) + c2*exp(-0.707106781186547*x) + c3*exp(0.707106781186547*x) + c4*exp(0.707106781186547*x)


## Example 13.5, page no. 402¶

In :
import numpy

print 'Solution to the given linear differntial equation is given by: '
m = numpy.poly()
f = m**2+5*m+6
y = numpy.exp(f)/numpy.polyval(f,1)
print "y = ", y

Solution to the given linear differntial equation is given by:
y =  [ 9041.93285661    22.41271075]


## Example 13.6, page no. 403¶

In :
import numpy, sympy

print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly()
f =(m+2)*(m-1)**2;
r = numpy.roots([2, -1, 2])
print r
print 'y = 1/f(D)∗[exp(-2x)+exp(x)-exp(-x)'
print 'using 1/f(D)exp(ax) = x/f1(D)∗exp(ax) if f(m)=0'
y1 = x*sympy.exp(-2*x)/9
y2 = sympy.exp(-x)/4
y3 = x**2*sympy.exp(x)/6
y = y1+y2+y3
print "y = ", y

Solution of the given linear equation is given by:
[ 0.25+0.96824584j  0.25-0.96824584j]
y = 1/f(D)∗[exp(-2x)+exp(x)-exp(-x)
using 1/f(D)exp(ax) = x/f1(D)∗exp(ax) if f(m)=0
y =  x**2*exp(x)/6 + x*exp(-2*x)/9 + exp(-x)/4


## Example 13.7, page no. 404¶

In :
import numpy, sympy

print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly()
f = m**3+1;
print '''Using the identity 1/f(D**2)∗sin(ax+b)[or cos(ax+b)]=1/f(-a**2)∗sin(ax+b)[or cos(ax+b)] this equation
can be redused to''',
print 'y = (4D+1)/65∗cos(2x-1)'
y = (sympy.cos(2*x-1)+4*sympy.diff(sympy.cos(2*x-1),x))/65
print "y = ", y

Solution of the given linear equation is given by:
Using the identity 1/f(D**2)∗sin(ax+b)[or cos(ax+b)]=1/f(-a**2)∗sin(ax+b)[or cos(ax+b)] this equation
can be redused to y = (4D+1)/65∗cos(2x-1)
y =  -8*sin(2*x - 1)/65 + cos(2*x - 1)/65


## Example 13.8, page no. 405¶

In :
import numpy, sympy

print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly()
f = m**3+4*m
print 'Using 1/f(D)exp(ax) = x/f1(D)∗exp(ax) if f(m)=0'
print 'y = x∗1/(3D**2+4)∗sin2x'
print '''Using this identity 1/f(D**2)∗sin(ax+b)[or cos(ax+b)]= 1/f(-a**2)∗sin(ax+b)[or cos (ax+b)] this equation
can be redused to''',
print 'y = -x/8∗sin2x'
x=1
y = -x*numpy.sin(2*x)/8
print "y = ", y

Solution of the given linear equation is given by:
Using 1/f(D)exp(ax) = x/f1(D)∗exp(ax) if f(m)=0
y = x∗1/(3D**2+4)∗sin2x
Using this identity 1/f(D**2)∗sin(ax+b)[or cos(ax+b)]= 1/f(-a**2)∗sin(ax+b)[or cos (ax+b)] this equation
can be redused to y = -x/8∗sin2x
y =  -0.113662178353


## Example 13.9, page no. 406¶

In :
import numpy, sympy

print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly()
print '''y = 1/(D(D+1))[x**2+2x+4] can be written as (1−D+D**2)/D[x**2+2x+4] which is combination of
differentialtion and integration'''
g = x**2+2*x+4
f = g-sympy.diff(g,x)+sympy.diff(g,x,2)
y = sympy.integrate(f,x)
print 'y = ', y

Solution of the given linear equation is given by:
y = 1/(D(D+1))[x**2+2x+4] can be written as (1−D+D**2)/D[x**2+2x+4] which is combination of
differentialtion and integration
y =  x**3/3 + 4*x


## Example 13.11, page no. 406¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
print 'CF + PI'
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
x = sympy.Symbol('x')
m = numpy.poly()
f = (m-2)**2;
r = numpy.roots([2, 2])
print r
print 'CF is given by: '
cf = (c1+c2*x)*sympy.exp(r*x)
print cf
print '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−'
print 'PI = 8∗{1/(D−2)**2[exp(2x)]+{1/(D−2)**2[sin(2x)]+{1/(D−2)**2[x**2]}'
print 'Using identitties it reduces to: ',
pi = 4*x**2*sympy.exp(2*x)+sympy.cos(2*x)+4*x+3
print pi
y = cf + pi ;
print 'The solution is y = ', y

Solution to the given linear differntial equation is given by:
CF + PI
[-1.]
CF is given by:
(c1 + c2*x)*exp(-1.0*x)
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
PI = 8∗{1/(D−2)**2[exp(2x)]+{1/(D−2)**2[sin(2x)]+{1/(D−2)**2[x**2]}
Using identitties it reduces to:  4*x**2*exp(2*x) + 4*x + cos(2*x) + 3
The solution is y =  4*x**2*exp(2*x) + 4*x + (c1 + c2*x)*exp(-1.0*x) + cos(2*x) + 3


## Exampe 13.12, page no. 407¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
print 'CF + PI'
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**2-4
r = numpy.roots([2, 0, 4])
print r
print 'CF is given by'
cf = c1*sympy.exp(r*x)+c2*sympy.exp(r*x)
print cf
print '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−'
print 'PI = 8∗{1/(D**2-4)[x∗sinh(x)]'
print 'Using identities it reduces to: ',
pi = -x/6*(sympy.exp(x)-sympy.exp(-x))-2/18*(sympy.exp(x)+sympy.exp(-x))
print pi
y = cf + pi
print "The solution is y = ", y

Solution to the given linear differntial equation is given by:
CF + PI
[-0.+1.41421356j  0.-1.41421356j]
CF is given by
c1*exp(1.4142135623731*I*x) + c2*exp(-1.4142135623731*I*x)
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
PI = 8∗{1/(D**2-4)[x∗sinh(x)]
Using identities it reduces to:  -x*(exp(x) - exp(-x))/6
The solution is y =  c1*exp(1.4142135623731*I*x) + c2*exp(-1.4142135623731*I*x) - x*(exp(x) - exp(-x))/6


## Example 13.13, page no. 408¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
print 'CF + PI'
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
x = sympy.Symbol('x')
m = numpy.poly()
f = m**2-1
r = numpy.roots([2, 0, 1])
print r
print 'CF is given by'
cf = c1*sympy.exp(r*x)+c2*sympy.exp(r*x)
print cf
print '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−'
print 'PI = -1/10∗{1/(D**2-1)[x∗sin(3x)+cos(x)]'
print 'Using identities it reduces to: ',
pi = -1/10*(x*sympy.sin(3*x)+3/5*sympy.cos(3*x))-sympy.cos(x)/2
print pi
y = cf + pi
print "The solution is y = ", y

Solution to the given linear differntial equation is given by:
CF + PI
[-0.+0.70710678j  0.-0.70710678j]
CF is given by
c1*exp(0.707106781186548*I*x) + c2*exp(-0.707106781186548*I*x)
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
PI = -1/10∗{1/(D**2-1)[x∗sin(3x)+cos(x)]
Using identities it reduces to:  -x*sin(3*x) - cos(x)/2
The solution is y =  c1*exp(0.707106781186548*I*x) + c2*exp(-0.707106781186548*I*x) - x*sin(3*x) - cos(x)/2


## Example 13.14, page no. 408¶

In :
import numpy, sympy

print 'Solution to the given linear differntial equation is given by: '
print 'CF + PI'
c1 = sympy.Symbol('c1')
c2 = sympy.Symbol('c2')
c3 = sympy.Symbol('c3')
c4 = sympy.Symbol('c4')
x = sympy.Symbol('x')
m = numpy.poly()
f =m**4+2*m**2+1
r = numpy.roots([4, 2, 2, 1])
print r
print 'CF is given by'
cf = ((c1+c2*x)*sympy.exp(r.real*x)+(c3+c4*x)*sympy.exp(r.real*x))
print cf
print '−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−'
print 'PI = ∗{1/(D**4+2∗D+1)[x**2∗cos(x)]'
print 'Using identities it reduces to: ',
pi = -1/48*((x**4-9*x**2)*sympy.cos(x)-4*x**3*sympy.sin(x))
print pi
y = cf + pi
print "The solution is y = ", y

Solution to the given linear differntial equation is given by:
CF + PI
(5.55111512313e-17+0.707106781187j)
CF is given by
(c1 + c2*x)*exp(5.55111512312578e-17*x) + (c3 + c4*x)*exp(-0.5*x)
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
PI = ∗{1/(D**4+2∗D+1)[x**2∗cos(x)]
Using identities it reduces to:  4*x**3*sin(x) - (x**4 - 9*x**2)*cos(x)
The solution is y =  4*x**3*sin(x) + (c1 + c2*x)*exp(5.55111512312578e-17*x) + (c3 + c4*x)*exp(-0.5*x) - (x**4 - 9*x**2)*cos(x)