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([0])
f = m**2+m-2
r = numpy.roots([2, 1, -2])
y = c1*sympy.exp(r[0]*x)+c2*sympy.exp(r[1]*x)
print "y = ", y
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([0])
f = m**2+6*m+9;
r = numpy.roots([2, 6, 9])
y =(c1+x*c2)*sympy.exp(r[0]*x)
print "y = ", y
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([0])
f = m**3+m*2+4*m+4;
r = numpy.roots([3, 2, 4, 4])
y = c1*sympy.exp(r[0].real*x)+c2*sympy.exp(r[1].real*x)+c3*sympy.exp(r[2].real*x)
print "y = ", y
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([0])
f = m**4+4;
r = numpy.roots([4, 0, 0, 0, 4])
y = c1*sympy.exp(r[0].real*x)+c2*sympy.exp(r[1].real*x)+c3*sympy.exp(r[2].real*x)+c4*sympy.exp(r[3].real*x)
print "y = ", y
import numpy
print 'Solution to the given linear differntial equation is given by: '
m = numpy.poly([0])
f = m**2+5*m+6
y = numpy.exp(f)/numpy.polyval(f,1)
print "y = ", y
import numpy, sympy
print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly([0])
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
import numpy, sympy
print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly([0])
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
import numpy, sympy
print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly([0])
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
import numpy, sympy
print 'Solution of the given linear equation is given by: '
x = sympy.Symbol('x')
m = numpy.poly([0])
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
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([0])
f = (m-2)**2;
r = numpy.roots([2, 2])
print r
print 'CF is given by: '
cf = (c1+c2*x)*sympy.exp(r[0]*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
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([0])
f = m**2-4
r = numpy.roots([2, 0, 4])
print r
print 'CF is given by'
cf = c1*sympy.exp(r[0]*x)+c2*sympy.exp(r[1]*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
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([0])
f = m**2-1
r = numpy.roots([2, 0, 1])
print r
print 'CF is given by'
cf = c1*sympy.exp(r[0]*x)+c2*sympy.exp(r[1]*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
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([0])
f =m**4+2*m**2+1
r = numpy.roots([4, 2, 2, 1])
print r[0]
print 'CF is given by'
cf = ((c1+c2*x)*sympy.exp(r[0].real*x)+(c3+c4*x)*sympy.exp(r[2].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