Solutions to Second & Third Order DEs
Solutions to Second & Third Order DEs
PRACTICAL-I
Plotting of second order solution family of differential equation
Solving Second order Ordinary Differential Equation:
2
y
Question 1: Solve second order differential equation d
+y=0.
dx2
Solution:
Solution:
Solution:
Solution:
Solution:
In[31]:= Needs["PlotLegends`"]
Sol=DSolve[y ''[x] +y[x]⩵0, y[x],
x]
sol1=Evaluate[y[x] /. Sol[[1]] /.{C[1] ->1, C[2] ->2}]
sol2=y[x] /. Sol[[1]] /.{C[1] ->1, C[2] ->5}
sol3=y[x] /. Sol[[1]] /.{C[1] -> -1, C[2] -> -4}
Plot[{sol1, sol2, sol3},{x,-10, 10},
PlotStyle-> {{Red, Thickness[0.01]},{Green, Thick},{Purple, Thickness[0.02]}},
PlotLegend→{sol1, sol2, sol3}]
Out[32]= {{y[x]→C[1]Cos[x] +C[2]Sin[x]}}
Out[33]= Cos[x] +2
+5 Sin[x] Out[35]= -
Cos[x] -4 Sin[x]
4
5 5 10
2 sin(x) +cos(x)
-2
-10
Out[36]=
5 sin(x) +cos(x)
-4
-4 sin(x) -cos(x)
2
y
Question 2: Solve second order differential equation d
+ dy
-6y=0 and plot its three solutions.
dx2 dx
Solution:
3
ⅇ
-3 x 2 x
Out[39]= +5ⅇ
-3 x 2 x
Out[40]= -ⅇ +5ⅇ
200
150
2.5ⅇ 2x 100
1 2
ⅇ-3x +5ⅇ
Out[41]= -50
2x
-2 -1
50
-100
5ⅇ 2x -ⅇ -3x
2
y
Question 3: Solve second order differential equation 4 d
+12 dy
+ 9y=0 and plot its four
solutions for-
dx2 dx
(i) C[1]=-1,C[2]=4
(ii) C[1]=3,C[2]=6
(iii) C[1]=-10,C[2]=7
(iv) C[1]=-1.5,C[2]=-5
Solution:
4
-2 -1 1 2
6ⅇ -3x/2 x+3ⅇ
-100
Out[65]= 7ⅇ -3x/2 x-10
-5ⅇ -3x/2 x- 1
2
y
Question 4: Solve second order differential equation d
-6 dy
+ 13y=0 and plot its any three
solutions.
dx2 dx
Solution:
5
Sin[2
-4
x] -2 2 4
-5.0×10 6
-1.0×10 7
4ⅇ 3x cos(2x) -ⅇ 3x
-1.5×10 7
3ⅇ 3x sin(2x) +6ⅇ 3
-2.0×10 7
Out[70]=
7ⅇ 3x cos(2x) -10
2
y
Question 5: Solve second order differential equation d
-2 dy
+ y=0 and plot its any five
solutions.
dx2 dx
Solution:
6
-3ⅇ x
-2ⅇ x
x Out[88]= -ⅇ x
+7ⅇ x
x Out[89]= -6ⅇ x
+ⅇ x
Out[90]
=
ⅇx + 2ⅇ x
x 5 3
100
50
3ⅇ x x+0.5
-2 2 4
-2ⅇ x x-3 ⅇ
Out[91]= -50
-
7ⅇ x x-ⅇ x
ⅇx x-6ⅇ x
2ⅇ x x + ⅇx
35
Plotting of Third Order Solution Family of Differential Equation :
3 2
y y
Question1: Solve third order differential equation d
-5 d
+8 dy
- 4y=0 and plot its any
three
dx3 dx2 dx
solution
s.
Solution
:
In[62]:= Needs["PlotLegends`"]
sol=DSolve[y '''[x] -5 y''[x] +8 y'[x] -4 y[x]⩵0, y[x], x]
sol1=Evaluate y[x] /. sol[[1]] /. C[1]→1, C[2]→0.5, C[3]→2
3
sol2=y[x] /. sol[[1]] /. C[1]→-1 2, C[2]→0, C[3]→1
sol3=y[x] /. sol[[1]] /.{C[1]→-1, C[2]→-4, C[3]→2}
Plot[{sol1, sol2, sol3},{x,-5, 3}, PlotRange-> {-30, 30},
PlotStyle-> {{Red, Thickness[0.01]},{Green, Thick},{Purple,
Thickness[0.02]}}, PlotLegend-> {sol1, sol2, sol3}]
Out[63]= y[x]→ ⅇ x C[1] +ⅇ 2 C[2]
x +ⅇ x C[3]
ⅇx ⅇ
2 x
Out[64]= 2 2 x
+0.5ⅇ + 3
x
ⅇx 2 x
Out[65]=
- +ⅇ
Out[66]= -ⅇx -4ⅇ2 +2ⅇ
x x
30
20
-2 2
ⅇ
2 2xx 10
x+ⅇ +0.5ⅇ -10
3
-
ⅇx
ⅇ2x x-
Out[67]=
-20
2
-30
2ⅇ 2x x-ⅇ x -4ⅇ 2x
3 2
y y
Question2: Solve third order differential equation d
+3 d
-25 dy
+21y=0 and plot its any
four
dx3 dx2 dx
solution
s.
Solution
:
2
ⅇ
-7 x 3 x
Out[44]= +2ⅇ
ⅇ-7 +ⅇ
Out[45]= -
1 3 x
x
2
-7 x x 3 x
Out[46]= -ⅇ -4ⅇ +2ⅇ
20
10
ⅇ3x - 1 ⅇ-7x
-10
Out[48]=
2
-20
-ⅇ-7x -4ⅇ x +
3 2
y y
Question3: Solve third order differential equation d
-4 d
-25 dy
+28y=0 and plot its any
four
dx3 dx2 dx
solution
s.
Solution
:
3
ⅇ
-4 x 7 x
Out[50]= +2ⅇ
4 x
+3ⅇ 7 x
Out[52]= -ⅇ - -
4ⅇ x
+20ⅇ 7 x
Out[53]= -
0.5ⅇ -4 x -2ⅇ x
+ⅇ 7 x
80
60
ⅇ-4x +2ⅇ 7x
20
-2ⅇ -4x +10ⅇ x 40
3 2
y y
Question4: Solve third order differential equation d
-13 d
+19 dy
+33y=cos(2x) and plot its
any four
dx3 dx2 dx
solution
s.
Solution
:
4
4×10 27
3×10 27
Out[61]= 2×
10ⅇ -x +3ⅇ 3x
-ⅇ-x -7ⅇ 3x +
1× 4.5 5.0 5.5 6.0
-10.5ⅇ -x +2ⅇ
Solution:
5
x,y
1
5 10 15 x[t]
Out[69]
= -1 t y[t]
-2
-3
1.0
0.5
Out[70]= -3 -2 -1 1 2 3
X
-0.5
-1.0
Out[71]=
t X
5 10 15
Solution:
2 ,
In[76]:= Sol1=NDSolve x'[t]⩵y[t], y'[t]⩵ 1- x[t] *y[t] -x[t], x[0]⩵1, y[0]⩵1
{x[t], y[t]},{t, 0, 30}
k1=Plot[{x[t] /. Sol1, y[t] /. Sol1},{t, 0, 25},
AxesLabel-> {"t", "x,y"}, PlotStyle-> {Blue, Red}]
k2=ParametricPlot[{x[t], y[t]} /. Sol1,{t, 0,
25}, AxesLabel-> {"X", "Y"},
PlotStyle→Dotted]
Show[GraphicsArray[{k1, k2}]]
6
Domain: {{0.,
x[t]→
Out[76]= [t],
30.}}
InterpolatingFunction
Output: scalar
x,y
1
5 10 15 20 25
Out[77]=
t
-1
-2
Out[78]
-2 -1 1 2
=
X
-1
-2
x,y
2
2
1
1
Out[79]
= t X
510152025 -2-1 12
-1
-1
-2
-2
Solution:
In[80]:= Sol2=DSolve[
{x'[t]⩵y[t], y'[t]⩵-5*x[t] -2*y[t] +1, x[0]⩵0, y[0]⩵-1},{x[t], y[t]}, t]
s1=Plot[{x[t] /. Sol2, y[t] /. Sol2},{t, 0, 3π}, AxesLabel-> {"t",
"x,y"}, PlotStyle-> {Pink, Cyan}, PlotLegends-> {"x[t]",
"y[t]"}]
s2=ParametricPlot[{x[t], y[t]} /. Sol2,{t, 0, 3π},
AxesLabel-> {"X", "Y"}, PlotStyle→Dashed, PlotRange-> {-1, 0.5}]
Show[GraphicsArray[{s1, s2}]]
ⅇ
1 -t
Out[80]= x[t]→ -Cos[2 t] +ⅇ t Cos[2 t]2 -3 Sin[2 t] +ⅇ t Sin[2
, t]2 5
t
y[t]→-ⅇ - Cos[2 t] -Sin[2 t]
x,y
0.4
0.2
x[t]
Out[81]
= 2 4 6 8 y[t]
t
-0.2
8
0.4
0.2
Out[82]= -0.4
-0.6
-0.8
-1.0
0.4
0.2
X
-1
.0 -0.5 0.5
Out[83]=
-0.2
t
-0.4
2468 -0.6
-0.8
-1.0
First Order Partial Differential Equation:
∂u ∂u
Q1. Solve the first order PDE x2 +y2 = (x+y)u .
∂x ∂y
In[5]:= DSolve[x ^ 2*D[u[x, y], x] +y ^ 2*D[u[x, y], y]⩵(x+y) *u[x, y], u[x, y],{x, y}]
Out[5]= u[x, y]→x y C[1] -
x y
∂u ∂u
Q2. Solve the first order PDE x +y = u .
∂x ∂y
In[6]:= DSolve[x*D[u[x, y], x] +y*D[u[x, y], y]⩵u[x, y], u[x, y],{x, y}]
Out[6]= u[x, y]→x C[1] y
x
∂u ∂u
Q3. Solve the first order PDE x +y = nu .
∂x ∂y
In[7]:= DSolve[x*D[u[x, y], x] +y*D[u[x, y], y]⩵n*u[x, y], u[x, y],{x, y}]
Out[7]=
y
u[x, y]→x n C[1]
x
In[8]:= sol=DSolve[{D[u[x, y], x] -D[u[x, y], y]⩵1, u[x, 0]⩵x ^ 2}, u[x, y],{x,
y}] Plot3D[u[x, y] /. sol,{x,-1, 1},{y,-1, 1}]
Out[8]= u[x, y]→x 2 -y+2 x y+y
Out[9]=
In[18]:= sol1=DSolve[
{x*D[u[x, y], x] +y*D[u[x, y], y]⩵x*ⅇ^(-u[x, y]), u[x, x ^ 2]⩵0}, u[x, y],
{x, y}] Plot3D[u[x, y] /. sol1,{x, 0, 2},{y, 0, 2}]
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
Out[18]= u[x, y]→Log 1+x- y
x
Out[19]=
2
Q6. Solve the PDE yux+xuy=0, u(0,y) =ⅇ -y
and plot the solution over the domain [-1,1]x[-
1,1].
3
u[x, y]→ ⅇ
x2 -y2
Out[16]=
Out[17]=
In[20]:= sol3=DSolve[{x*D[u[x, y], x] +y*D[u[x, y], y]⩵2*x*y, u[x, x^ 2]⩵2}, u[x, y],{x,
y}] Plot3D[u[x, y] /. sol3,{x, 1, 2},{y,-2, 2}]
2 x3 +x 4 y-y 3
Out[20]= [
u ]→
x3
Out[21]=
Q8. Solve the PDE ux+xuy=0, u(0,y) =Siny and plot the solution over the domain [-5,5]x[-5,5].
4
In[24]:= sol4=DSolve[{D[u[x, y], x] +x*D[u[x, y], y]⩵0, u[0, y]⩵Sin[y]}, u[x, y],
{x, y}] Plot3D[u[x, y] /. sol4,{x,-5, 5},{y,-5, 5}]
Plot[u[x, y] /. sol4/. x→1,{y,-5, 5}]
Plot[u[x, y] /. sol4/. y→1,{x,-5, 5}]
Out[24]= u[x, y]→Sin 1 -x +2 y
2
Out[25]=
1.0
0.5
Out[26]=
-4 -2 2
-0.5
1.0
0.5
Out[27]=
-4 -2 2
-0.5
5
In[28]:= sol5=DSolve
D[u[x, y], x] +x*D[u[x, y], y]⩵ y- 1 2 x^ 2 ^2, ,
u[x, y],{x, y}
u[0, y]⩵ⅇ^y
2
4ⅇ
2 2 2
Out[28]=
4
Out[29]=
Q10. Solve the PDE uux -uu y =u^ 2+ (x+y) 2, u(x, 0) =1 and plot the solution over
the domain [-2,2]x[-2,2].
6
In[30]:= sol6=DSolve[{u[x, y] *D[u[x, y], x] -u[x, y] *D[u[x, y], y]⩵u ^ 2+ (x+y)^ 2, u[x,
0]⩵1}, u[x, y],{x, y}]
Plot3D[u[x, y] /. sol6,{x,-2, 2},{y,-2, 2}]
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
General: Further output of Solve::ifun will be suppressed during this calculation.
Out[31]=
In[32]:= sol7=
DSolve[{D[u[x, y], x] +x*D[u[x, y], y]⩵u[x, y] +1, u[x, x^ 2]⩵x ^ 2}, u[x, y],
{x, y}] Plot3D[u[x, y] /. sol7,{x,-2, 2},{y, 1, 5}]
-x2+2 y -x2+2 y -x2+2 y
Out[32]= u[x, y]→-1+ⅇ x+ -ⅇ x+ x2 +2ⅇ x+
y
Out[33]=
Finding the Characteristic Equation for First Order PDE and Solving Them:
∂u ∂u
Example1: Find the characteristic curves of the equation x + y =u and plot them.
∂x ∂y
Solution: The characteristic equations dy du
are dx = = .
x y u
Using (i)=(ii) and integrating, we
have, ϕ= y =C , is the first integral.
1
x
10
5
y=x
Out[1]
-4 -2 2 4 y=2x
=
x
-5 y=3x
-10
2
10
u=x
Out[2]
-4 -2 2 4 u=2x
=
x
-5 u=3x
-10
y=x
Out[3]= y=2x
y=3x
3
Out[4]=
4
Out[5]=
∂u ∂u
Example2: Find the characteristic curves of the equation - =1 and plot them.
∂x ∂y
Solution: The characteristic equations are dx
= dy
= du
.
1 -1 1
Using (i)=(ii) and integrating, we
have, ϕ=x+ y=C 1, is the first
integral.
2.5
x+y=
2.0
Out[6] 1
=
x+y=
1.5 2
x+y=
1.0 3
0.5
x
0.0 0.5 1.0 1.5 2.0 2.5 3.0
u-
6
Out[7] x=1
=
4 u-
x=2
2
u-
-4 -2
x=3
2 4
-2 x
6
Out[10]=
x+y=1
x+y=2
x+y=3
u-
Out[11]= x=1
u-x=2
u-x=3
7
In[12]:= ParametricPlot3D[{{t, 1-t, u},{t, 2-t, u},{t, 3-t, u}},{t,-5, 5},{u,-4, 4}]
Out[12]=
Out[13]=
8
∂u ∂u
Example3: Find the characteristic curves of the equation x2 + y2 =(x+y)u and plot them.
∂x ∂y
Solution: The characteristic equations are dx
dy
=(x+y)u
= du
.
x2 y2
Characteristic Curves
y
0.5
-3 -2 -1 1 2 3 y-x
x xy=1
-0.5 y-x
xy=2
Out[14]
=
-1.0 y-x
xy=3
-1.5
9
u
x-y=1
u
Out[15]=
=2
x-y
u
=3
x-y
SOLUTION OF DIFFERENTIAL EQUATION BY VARIATION OF
PARAMETER METHOD:
In[3]:= y1=Exp[2*x]
ⅇ
2 x
Out[3]=
In[4]:= y2=Exp[3*x]
ⅇ
3 x
Out[4]=
In[6]:= r=2*Exp[x]
x
Out[6]= 2ⅇ
In[9]:= yp=y1*v1+y2*v2
Out[9]= ⅇx
In[10]:= Sol=yc+yp
ⅇx + y[x]→ ⅇ
2 x 3 x
Out[10]
= C[1] +ⅇ C[2]
In[48]:= y1=Cos[2 x]
Out[48]= Cos[2 x]
In[49]:= y2=Sin[2 x]
Out[49]= Sin[2 x]
2
In[51]:= r=Sec x
2
Out[51]= Sec x
Out[52]= - - 1 1
Sec 2 x Cos[2 x] +
Sin[2 x] 4 8
In[55]:= 4 8 2 4 2
Sol=yc+yp
Out[55]= y[x]→C[1]Cos[2 x] +C[2]Sin[2 x]
1 -
1 1 1 1
Sec2 Cos[2 x Cos[2 x] + Sec2 Sin[2 x] Cos[2 x] + x Sin[2 x]
x] - +
Sin[2 x]
In[69]:= y1=Cos[x]
Out[69]= Cos[x]
In[70]:= y2=Sin[x]
Out[70]= Sin[x]
3
In[72]:= r=Tan[x]
Out[72]= Tan[x]
In[76]:= Sol=yc+yp
Out[76]= y[x]→C[1]Cos[x] +C[2]Sin[x] -Cos[x]Sin[x] +
x x x x
Cos[x] Log Cos -Sin -Log Cos +Sin +Sin[x]
2 2 2 2
ⅇ C[1] +C[2]
Out[96]= y[x]→
1 2
x
2
ⅇ2
1 x
In[105]:= y1=
ⅇ2
2
Out[105]=
x
2
In[106]:=
y2=1
Out[106]= 1
x
In[109]:= r=ⅇ Sin[x]
ⅇ Sin[x]
x
Out[109]=
In[113]:= Sol=yc+yp
ⅇ C[1]
Out[113]= y[x]→ 1 1 1
ⅇ ⅇ
2
-Cos[x] Cos[x] +Sin[x]
x x
x +C[2] - +Sin[x] -
2 4 4
Plot the Integral Surface of a given First Order PDE with the Initial Data:
Out[3]=
y]⩵2*x*u[x, y]
sol2=DSolve[{pde, u[0, y]⩵y ^ 3}, u[x, y],{x, y}]
Plot3D[u[x, y] /. sol2,{x,-7, 7},{y,-5, 5},
PlotLabel→"Integral Surface through initial curve"]
0,1) (1,0) [x,
Out[4]= -2 x y u ( [x, y] +y u y]⩵2 x u[x, y]
2 4
Out[5]= u[x, y]→ x
y
Out[6]=
2
Out[8]= u[x,
y]→- -2+x+y
Out[9]
=
Out[12]=
In[13]:= Eqn2=u[x, y] * (x+y) *D[u[x, y], x] +u[x, y] * (x-y) *D[u[x, y], y]⩵x 2
Solve: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for
complete solution information.
2
Out[14]= u[x, 2 x2 +3 x y-2 , u[x, y]→ 2 2 x2 +3 x y-2 y 2 ,
y]→- y 2
7
7
u[x, 2 2 2 x2 +3 x y-2 y 2
2 x2 +3 x y-2 , u[x, y]→ 7
y]→- 2
y
7
Out[15]
=
Out[18]=
Out[21]=
u[x, y]→ ⅇ
2
Out[23]= -(-2 x+y)
Out[24]=