0% found this document useful (0 votes)
23 views27 pages

Solutions to First and Second Order PDEs

The document outlines practical exercises for solving first and second order Partial Differential Equations (PDEs) using various methods, including characteristics and initial conditions. It includes specific examples, solutions, and plots for different PDEs, demonstrating the application of differential equations in mathematical modeling. Additionally, it covers the Cauchy problem for first order PDEs, providing solutions and visualizations for better understanding.

Uploaded by

ahanakbuss98
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views27 pages

Solutions to First and Second Order PDEs

The document outlines practical exercises for solving first and second order Partial Differential Equations (PDEs) using various methods, including characteristics and initial conditions. It includes specific examples, solutions, and plots for different PDEs, demonstrating the application of differential equations in mathematical modeling. Additionally, it covers the Cauchy problem for first order PDEs, providing solutions and visualizations for better understanding.

Uploaded by

ahanakbuss98
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practical 1 : General solution of first

and second order Partial Differential


Equations
(A) Solutions of First Order PDEs

Q1. Find the general solution of the following first order PDE : ux + uy = 0.

Pde = D[u[x, y], x] + D[u[x, y], y]  0


O u t [ ] =

u(0,1) [x, y] + u(1,0) [x, y]  0

I n [ ] : = Sol = DSolve[Pde, u[x, y], {x, y}]


O u t [ ] =

{{u[x, y]  1 [- x + y]}}

I n [ ] : = f[x_, y_] = u[x, y] /. Sol〚1〛


O u t [ ] =

1 [- x + y]

I n [ ] : = f[x, 0]
O u t [ ] =

1 [- x]

Q2. Find the general solution of the following first order PDE : x ux + y uy = u .

I n [ ] : = Pde = x D[u[x, y], x] + y D[u[x, y], y]  u[x, y]


O u t [ ] =

y u(0,1) [x, y] + x u(1,0) [x, y]  u[x, y]

I n [ ] : = Sol = DSolve[{Pde}, u[x, y], {x, y}]


O u t [ ] =
y
u[x, y]  x 1  
x
2 [Link]

Q3. Plot the solution of the following PDE : ux + uy = 0, u[0, y] = Sin y.

I n [ ] : = Sol = DSolve[{D[u[x, y], x] + D[u[x, y], y]  0, u[0, y]  Sin[y]}, u[x, y], {x, y}]
O u t [ ] =

{{u[x, y]  - Sin[x - y]}}

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 5, 5}, {y, - 5, 5}, AxesLabel  {x, y, u}]


O u t [ ] =

Q4. Plot the solution of the following first order PDE : x ux + y uy = x e-u , , u (x, y)
= 0 on y = x 2.

I n [ ] : = Pde = x D[u[x, y], x] + y D[u[x, y], y]  x Exp[- u[x, y]]


O u t [ ] =

y u(0,1) [x, y] + x u(1,0) [x, y]  -u[x,y] x

I n [ ] : = Sol = DSolvePde, u[x, y] /. y  x2   0, u[x, y], {x, y} // Quiet


O u t [ ] =
y
u[x, y]  Log1 + x - 
x
[Link] 3

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 5, 5}, {y, - 5, 5},


AxesLabel  {x, y, u}, ColorFunction  "Rainbow"]
O u t [ ] =

(B) Solutions of Second Order PDEs

Q5. Find general solutions of the following Second order


PDE : uxx + 2 uxy + uyy = 0.

I n [ ] : = Pde = D[u[x, y], {x, 2}] - 2 D[u[x, y], x, y] + D[u[x, y], {y, 2}]  0
O u t [ ] =

u(0,2) [x, y] - 2 u(1,1) [x, y] + u(2,0) [x, y]  0

I n [ ] : = Sol = DSolve[Pde, u[x, y], {x, y}]


O u t [ ] =

{{u[x, y]  1 [x + y] + x 2 [x + y]}}

Q6. Find solution of the following Second order PDE : uxx+ 2 uxy - 3 uyy = 0, u[x,
0] = Sin x, uy [x, 0] = x .

I n [ ] : = Pde = D[u[x, y], {x, 2}] + 2 D[u[x, y], x, y] - 3 D[u[x, y], {y, 2}]  0
O u t [ ] =

- 3 u(0,2) [x, y] + 2 u(1,1) [x, y] + u(2,0) [x, y]  0


4 [Link]

I n [ ] : = Sol = DSolve[{Pde, (u[x, y] /. y  0)  Sin[x], (D[u[x, y], y] /. y  0)  x},


u[x, y], {x, y}] // FullSimplify
O u t [ ] =
1 y
u[x, y]  4 y (3 x + y) + 9 Sinx -  + 3 Sin[x + y] 
12 3

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 5, 5}, {y, - 5, 5},


AxesLabel  {x, y, u}, ColorFunction  "Rainbow"]
O u t [ ] =
[Link] 5

Practical 2 : Solution and Plotting of


Cauchy Problem for the first order
PDEs
Q 1. Obtain the solution of the linear equation u x - uy = 1,
with the data u (x, 0) = x2.

I n [ ] : = Pde = D[u[x, y], x] - D[u[x, y], y]  1


O u t [ ] =

- u(0,1) [x, y] + u(1,0) [x, y]  1

I n [ ] : = Sol = DSolvePde, u[x, 0]  x2 , u[x, y], {x, y}


O u t [ ] =

u[x, y]  x2 - y + 2 x y + y2 

I n [ ] : = Ch = D[y[x], x]  - 1
O u t [ ] =

y′ [x]  - 1

I n [ ] : = chSol = DSolve[Ch, y[x], x]


O u t [ ] =

{{y[x]  - x + 1 }}

I n [ ] : = Plot[y[x] /. chSol /. C[1]  Range[0, 4],


{x, - 4, 4}, Frame  True, FrameLabel  "Characteristics"]
O u t [ ] =

-2

-4
-4 -2 0 2 4
Characteristics
6 [Link]

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 4, 4}, {y, - 4, 4},


PlotLabel  "Integral Surface", ColorFunction  "Rainbow"]
O u t [ ] =

Q 2. Obtain the solution of the linear equation u x + 2 uy = 0,


2
with the cauchy data u (0, y) = e-y .

I n [ ] : = Pde = D[u[x, y], x] + 2 D[u[x, y], y]  0


O u t [ ] =

2 u(0,1) [x, y] + u(1,0) [x, y]  0

I n [ ] : = Sol = DSolvePde, u[0, y]  Exp- y2 , u[x, y], {x, y}


O u t [ ] =
2
u[x, y]  -(-2 x+y) 

I n [ ] : = Ch = D[y[x], x]  2
O u t [ ] =

y′ [x]  2

I n [ ] : = ChSol = DSolve[Ch, y[x], x]


O u t [ ] =

{{y[x]  2 x + 1 }}
[Link] 7

I n [ ] : = Plot[y[x] /. ChSol /. C[1]  Range[0, 4], {x, - 4, 4},


Frame  True, FrameLabel  "Characteristics", PlotStyle  Blue]
O u t [ ] =

10

-5

-4 -2 0 2 4
Characteristics

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 10, 10}, {y, - 10, 10},


PlotLabel  "Integral Surface", ColorFunction  "Rainbow"]
O u t [ ] =

Q 3. Obtain the solution of the equation u (x + y) ux + u (x - y) uy =


x2 + y2, with the data u (x, 2 x) = 0.

I n [ ] : = Pde = u[x, y] (x + y) D[u[x, y], x] + u[x, y] (x - y) D[u[x, y], y]  x2 + y2


O u t [ ] =

(x - y) u[x, y] u(0,1) [x, y] + (x + y) u[x, y] u(1,0) [x, y]  x2 + y2

I n [ ] : = Sol = DSolve[{Pde, (u[x, y] /. y  2 x)  0}, u[x, y], {x, y}] // Quiet


O u t [ ] =

2 2
u[x, y]  - 2 x2 + 3 x y - 2 y2 , u[x, y]  2 x2 + 3 x y - 2 y2 ,
7 7

2 2
u[x, y]  - 2 x2 + 3 x y - 2 y2 , u[x, y]  2 x2 + 3 x y - 2 y2 
7 7
8 [Link]

x - y[x]
I n [ ] : = Ch = D[y[x], x] 
x + y[x]

O u t [ ] =
x - y[x]
y′ [x] 
x + y[x]

I n [ ] : = ChSol = DSolve[Ch, y[x], x]


O u t [ ] =

y[x]  - x - 2 1 + 2 x2 , y[x]  - x + 2 1 + 2 x2 

I n [ ] : = Plot[y[x] /. ChSol /. C[1]  Range[- 2, 2], {x, - 2, 2},


Frame  True, FrameLabel  "Characteristics", PlotStyle  Blue]
O u t [ ] =
10

-5

-10
-2 -1 0 1 2
Characteristics

I n [ ] : = Plot3D[u[x, y] /. Sol, {x, - 10, 10}, {y, - 10, 10},


PlotLabel  "Integral Surface", ColorFunction  "AlpineColors"]
O u t [ ] =
[Link] 9

Practical 3 : Plotting the


characteristics for the first order
partial differential equations
Q 1. Plot the characteristics for the following
first order PDE : ux + uy = 0, u (x, 0) = f (x).

I n [ ] : = Pde = D[u[x, y], x] + D[u[x, y], y]  0


O u t [ ] =

u(0,1) [x, y] + u(1,0) [x, y]  0

I n [ ] : = Chsys = {x '[t]  1, y '[t]  1, u '[t]  0};

I n [ ] : = Sol = DSolve[{Chsys, x[0]  x0, y[0]  0, u[0]  f[x0]}, {x[t], y[t], u[t]}, t]
O u t [ ] =

{{x[t]  t + x0, y[t]  t, u[t]  f[x0]}}

(*Define range of intitial x0 value*)

I n [ ] : = x0list = Range[- 5, 5, 2];

I n [ ] : = ParametricPlot[Evaluate @ Table[{t + x0, t}, {x0, x0list}], {t, 0, 5},


PlotStyle  {Green, Purple, Red, Blue, Orange}, PlotLegends  x0list,
Frame  True, FrameLabel  {"x", "t"}, PlotRange  {{- 5, 5}, {0, 5}}]
O u t [ ] =
5

4 -5
-3
3
-1
t

2
1
1 3

0
5
-4 -2 0 2 4
x
10 [Link]

Q 2. Plot the characteristics for the following first order PDE : u ux + uy = 0, u (x,
0) = g (x).

I n [ ] : = Pde = u[x, y] × D[u[x, y], x] + D[u[x, y], y]  0


O u t [ ] =

u(0,1) [x, y] + u[x, y] u(1,0) [x, y]  0

I n [ ] : = Chsys = {x '[t]  u[t], y '[t]  1, u '[t]  0};

I n [ ] : = Sol = DSolve[{Chsys, x[0]  x0, y[0]  0, u[0]  g[x0]}, {x[t], y[t], u[t]}, t]
O u t [ ] =

{{u[t]  g[x0], x[t]  x0 + t g[x0], y[t]  t}}

I n [ ] : = (*Define range of intitial x0 value*)


x0list = Range[- 5, 5, 2];

I n [ ] : = (*Define function g(x)*)


g[x_] = x;

I n [ ] : = ParametricPlot[Evaluate @ Table[{x0 + t g[x0], t}, {x0, x0list}], {t, 0, 10},


PlotStyle  {Red, Blue, Green, Purple, Orange}, PlotLegends  x0list,
Frame  True, FrameLabel  {"x", "t"}, PlotRange  {{- 10, 10}, {0, 10}}]
O u t [ ] =
10

8
-5

6 -3
-1
t

4
1

2
3
5
0
-10 -5 0 5 10
x

[Link] the Characteristics for


the following first order PDE : ux + uy = u,
2
u (x, 0) = h (x), where h (x) = e-x .

I n [ ] : = Pde = D[u[x, y], x] + D[u[x, y], y]  u[x, y]


O u t [ ] =

u(0,1) [x, y] + u(1,0) [x, y]  u[x, y]

I n [ ] : = Chsys = {x '[t]  1, y '[t]  1, u '[t]  u[t]};


[Link] 11

I n [ ] : = Sol = DSolve[{Chsys, x[0]  x0, y[0]  0, u[0]  h[x0]}, {x[t], y[t], u[t]}, t]
O u t [ ] =

x[t]  t + x0, y[t]  t, u[t]  t h[x0]

I n [ ] : = (*Define range of intitial x0 value*)


x0list = Range[1, 5, 1];

I n [ ] : = (*Define function h(x)*)


h[x_] = Exp- x2 ;

I n [ ] : = ParametricPlot[Evaluate @ Table[{Exp[t] h[x0], t}, {x0, x0list}], {t, 0, 10},


PlotStyle  {Red, Blue, Green, Purple, Orange}, PlotLegends  x0list,
Frame  True, FrameLabel  {"u", "t"}, PlotRange  {{0, 10}, {0, 10}}]
O u t [ ] =
10

6
1
2
t

3
4
4
5
2

0
0 2 4 6 8 10
u
12 [Link]

Practical 4 : Solution of vibrating


string problem using D’Alembert
formula with initial conditions.
The PDE is :
utt = c2 uxx, xϵ (0, L), t > 0
with initial conditions
u (x, 0) = f (x), ut (x, 0) = g (x)
The D ' Alembert Solution is :
u (x, t) =
x+ct
1 / 2[f (x + ct) + f (x - ct)] + 1 / (2 c)  g (s)  s
x-ct

I n [ ] : = (*Parameters*)c = 1;(*wave speed*)


L = 10;(*String length*)
(*Initial displacement and Velocity*)
f[x_] := Exp[- (x - 5) ^ 2](*Gaussian hump*)
g[x_] := 0 (*Zero initial velocity*)
(*D'Alembert Solution*)
u[x_, t_] := 1 / 2 (f[x - c t] + f[x + c t]) + 1 / (2 c) Integrate[g[s], {s, x - c t, x + c t}]
(*Simplify solution since g[x]=0 here*)
usol[x_, t_] = Simplify[u[x, t]]
O u t [ ] =
1 2 2
-(5+t-x) + -(-5+t+x) 
2
[Link] 13

I n [ ] : = (*Plot Displacement at a fixed Time *)


Plot[usol[x, 2], {x, 0, L}, PlotRange  All, Frame  True, FrameLabel  "String at t=2"]
O u t [ ] =

0.5

0.4

0.3

0.2

0.1

0.0

0 2 4 6 8 10
String at t=2

I n [ ] : = (* Animate Evolution of string *)


Manipulate[Plot[usol[x, t], {x, 0, L} , PlotRange  {- 1, 1}, AxesLabel  {"x", "u(x,t)"},
PlotLabel  Row[{"Vibrating String at t=", t}]], {t, 0, 10}]
O u t [ ] =

Vibrating String at t=0


u(x,t)
1.0

0.5

x
2 4 6 8 10

-0.5

-1.0
14 [Link]

I n [ ] : = (*Parameters*)c = 1;(*wave speed*)


L = 10;(*String length*)
(*Initial displacement and Velocity*)
f[x_] := Exp[- (x - 5) ^ 2] (*Gaussian hump*)
g[x_] := 1 (*Zero initial velocity*)
(*D'Alembert Solution*)
u[x_, t_] := 1 / 2 (f[x - c t] + f[x + c t]) + 1 / (2 c) Integrate[g[s], {s, x - c t, x + c t}]
(*Simplify solution since g[x]=0 here*)
usol[x_, t_] = Simplify[u[x, t]]
O u t [ ] =
1 2 2
-(5+t-x) + -(-5+t+x)  + t
2

I n [ ] : = (*Plot Displacement at a fixed Time *)


Plot[usol[x, 2], {x, 0, L}, PlotRange  All, Frame  True, FrameLabel  "String at t=2"]
O u t [ ] =

2.5

2.4

2.3

2.2

2.1

2.0

0 2 4 6 8 10
String at t=2
[Link] 15

I n [ ] : = (* Animate Evolution of string *)


Manipulate[Plot[usol[x, t], {x, 0, L} , PlotRange  {- 1, 1}, AxesLabel  {"x", "u(x,t)"},
PlotLabel  Row[{"Vibrating String at t = ", t}]], {t, 0, 10}]
O u t [ ] =

Vibrating String at t = 0
u(x,t)
1.0

0.5

x
2 4 6 8 10

-0.5

-1.0

In[1]:= (*Parameters*)c = 1;(*wave speed*)


L = 10;(*String length*)
(*Initial displacement and Velocity*)
f[x_] := Sin[x] (*Gaussian hump*)
g[x_] := x2 (*Zero initial velocity*)
(*D'Alembert Solution*)
u[x_, t_] := 1 / 2 (f[x - c t] + f[x + c t]) + 1 / (2 c) Integrate[g[s], {s, x - c t, x + c t}]
(*Simplify solution since g[x]=0 here*)
usol[x_, t_] = Simplify[u[x, t]]
t3
Out[6]= + t x2 + Cos[t] Sin[x]
3
16 [Link]

In[7]:= (*Plot Displacement at a fixed Time *)


Plot[usol[x, 5], {x, 0, L}, PlotRange  All, Frame  True, FrameLabel  "String at t=2"]

500

400

300

Out[7]=

200

100

0 2 4 6 8 10
String at t=2

In[8]:= (* Animate Evolution of string *)


Manipulate[Plot[usol[x, t], {x, 0, L} , PlotRange  {- 1, 1}, AxesLabel  {"x", "u(x,t)"},
PlotLabel  Row[{"Vibrating String at t = ", t}]], {t, 0, 1}]

Vibrating String at t = 0
u(x,t)
1.0

0.5
Out[8]=

x
2 4 6 8 10

-0.5

-1.0
[Link] 17

Practical 5 :
Solution of heat equation
ut = kuxx with
intitial conditions
The hear equation is :
ut = k uxx, x ∈ (0, L), t > 0
where :
u (x, t) -> temperature at position x and time t, k -> thermal diffusivity constant .
Initial Conditions : u (x, 0) = f (x),
0 < x < L . Boundary conditions
(i) Dirichlet (Fixed Temperature) Conditions
u (0, t) = ϕ1 (t) and u (L, t) = ϕ2 (t)
(ii) Neumann (Insulated/Specified Heat Flux) conditions
ux (0, t) = ψ1 (t) and ux (L, t) = ψ2 (t)
(iii) Robin (Mixed type) conditions
a1 u (0, t) + b1 ux (0, t) = g1 (t), a2 u (L, t) + b2 ux (L, t) = g2 (t)

Q .1 : Solve and plot the solution of following heat equation :


ut - uxx = 0, 0 < x < 5, t > 0,
u (x, 0) = 0, 0 < x < 5, u (0, t) = Sin t,
t ≥ 0, u (5, t) = 0, t ≥ 0.

I n [ ] : = Pde = D[u[x, t], t] - D[u[x, t], {x, 2}]  0


O u t [ ] =

u(0,1) [x, t] - u(2,0) [x, t]  0


18 [Link]

I n [ ] : = Sol =
DSolve[{Pde, u[x, 0]  0, u[0, t]  Sin[t], u[5, t]  0}, u[x, t], {x, t}] /. K[1]  n /.
∞5
O u t [ ] =
1
- n 2 π2 t nπx
5 50  25 n2 π2 - 50 n2 π2 Cos[t] - 1250 Sin[t] Sin 
1 5
u[x, t]  - (- 5 + x) Sin[t] +  
5 n=1 625 n π + n5 π5

I n [ ] : = a1[x_, t_] = u[x, t] /. Sol〚1〛 // Activate


O u t [ ] =
π2 t
- πx
50  25 π2 - 50 π2 Cos[t] - 1250 Sin[t] Sin 
1 5
- (- 5 + x) Sin[t] + +
5 625 π + π5
4 π2 t
- 2πx
200  25 π2 - 200 π2 Cos[t] - 1250 Sin[t] Sin 
5
+
1250 π + 32 π5
9 π2 t
- 3πx
450  25 π2 - 450 π2 Cos[t] - 1250 Sin[t] Sin 
5
+
1875 π + 243 π5
16 π2 t
- 4πx
800  25 π2 - 800 π2 Cos[t] - 1250 Sin[t] Sin 
5
+
2500 π + 1024 π5
2
t
1250 -π π2 - 1250 π2 Cos[t] - 1250 Sin[t] Sin[π x]

3125 π + 3125 π5

I n [ ] : = Plot3D[a1[x, t], {x, 0, 5}, {t, 0, 10}, AxesLabel  {"x", "t", "u(x,t)]"}]
O u t [ ] =
[Link] 19

Q .2 : Solve and plot the solution of following heat equation :


ut - 4 uxx = 0, 0 < x < 2, t > 0,
u (x, 0) = x2 (1 - x), 0 < x < 2, u (0, t) = 0,
t ≥ 0, u (1, t) = 0, t ≥ 0.

I n [ ] : = Pde = D[u[x, t], t] - 4 D[u[x, t], {x, 2}]  0


O u t [ ] =

u(0,1) [x, t] - 4 u(2,0) [x, t]  0

I n [ ] : = Sol = DSolvePde, u[x, 0]  x2 (1 - x), u[0, t]  0, u[2, t]  0, u[x, t], {x, t} /.
K[1]  n /. ∞  3
O u t [ ] =
2
π2 t nπx
3 8 -n - 2 - 10 (- 1)n + (- 1)n n2 π2  Sin 
2
u[x, t]   
n=1 n 3 π3

I n [ ] : = a1[x_, t_] = u[x, t] /. Sol〚1〛 // Activate


O u t [ ] =
2 πx 2 3πx
t
8 -π t
8 - π2  Sin  -4 π
2
t
- 12 + 4 π2  Sin[π x] 8 -9 π 8 - 9 π2  Sin 
2 2
+ +
π3 π3 27 π3

I n [ ] : = Plot3D[a1[x, t], {x, 0, 2}, {t, 1, 3},


AxesLabel  {"x", "t", "u(x,t)]"}, ColorFunction  "Rainbow"]
O u t [ ] =
20 [Link]

Practical 6 : Solution of one


dimensional wave equation with
initial conditions
(i) : u (x, 0) = f (x), ut (x, 0) = g (x), x ∈ , t > 0.

I n [ ] : = Pde = D[u[x, t], {t, 2}]  c2 D[u[x, t], {x, 2}];

I n [ ] : = (*Solution of the PDE analytically*)


Sol = DSolveValue[{Pde, u[x, 0]  f[x], Derivative[0, 1][u][x, 0]  g[x]}, u[x, t], {x, t}]
O u t [ ] =
c2 t+x
∫ g[K[1]]×K[1]
1 2 2 - c2 t+x
f- c t + x + f c t + x + t≥0
2 2 c2
Indeterminate True

I n [ ] : = (*Define initial data*)


f[x_] := Exp- x2 ;

I n [ ] : = g[x_] := 1;

I n [ ] : = (*sol is a Piecewise result;extract only the first branch (t≥0)*)


uExpr1 = Sol〚1, 1〛 /. c  1 // Activate
O u t [ ] =
1 2 2
 -(-t+x) + -(t+x)  + t, t ≥ 0
2
[Link] 21

I n [ ] : = (*3D surface plot of the solution*)


Plot3D[uExpr1, {x, - 8, 8}, {t, 0, 5}, AxesLabel  {"x", "t", "u(x,t)"},
PlotLabel  "1D Wave Equation Solution", ColorFunction  "BrightBands", PlotRange  All]
O u t [ ] =

(ii) : u (x, 0) = f (x), ut (x, 0) = g (x), u (0, t) = 0, x ∈ , t > 0.

I n [ ] : = Pde = D[u[x, t], {t, 2}]  c ^ 2 D[u[x, t], {x, 2}];

I n [ ] : = (*Solution of the PDE analytically*)Sol = DSolveValue[


{Pde, u[x, 0]  f[x], Derivative[0, 1][u][x, 0]  g[x], u[0, t]  0}, u[x, t], {x, t}]
O u t [ ] =
c2 t+x
∫ g[K[1]]×K[1]
1 2 2 c2 t+x
c2 t ≥ 0
-
f- c t + x + f c t + x + x>
2 2 c2
c2 t+x
∫ g[K[1]]×K[1]
1 c2 t-x
- f c2 t - x + f c2 t + x + 0≤x≤ c2 t
2 2 c2
Indeterminate True

I n [ ] : = Sol /. f[x_]  Exp- x2 , g[x_]  1


O u t [ ] =
2 2
1 -- c2 t+x - c2 t+x
 + +t x> c2 t ≥ 0
2
2 2
1 - c2 t-x - c2 t+x x
- + + 0≤x≤ c2 t
2 c2
Indeterminate True
22 [Link]

I n [ ] : = Manipulate[Plot3D[%3, {t, 0, 8}, {x, 0, 8},


AxesLabel  {"x", "t", "u(x,t)"}, PlotLabel  "1D Wave Equation Solution",
ColorFunction  "BrightBands", PlotRange  All], {c, 1, 2}]
O u t [ ] =

(iii) : u (x, 0) = f (x), ut (x, 0) = g (x), ux (0, t) = 0, x ∈ , t > 0.

I n [ ] : = Pde = D[u[x, t], {t, 2}]  c ^ 2 * D[u[x, t], {x, 2}];

I n [ ] : = DSolveValue[{Pde, u[x, 0]  f[x], Derivative[0, 1][u][x, 0]  g[x],


Derivative[1, 0][u][0, t]  0}, u[x, t], {x, t}] // Simplify
O u t [ ] =

f[x] x ≥ 0 && t  0
∞ ∞ Sin c2 t K[1] ∫0∞ Cos[x K[1]] g[x] x
2 ∫0 Cos[x K[1]] Cos c2 t K[1] ∫0 Cos[x K[1]] f[x] x+ K[1]
c2 K[1]
x ≥ 0 && t > 0
π
Indeterminate True
[Link] 23

I n [ ] : = Sol = DSolveValue[{Pde, u[x, 0]  Sin[x], Derivative[0, 1][u][x, 0]  x ^ 2,


Derivative[1, 0][u][0, t]  0}, u[x, t], {x, t}] // Simplify
O u t [ ] =
c2 t3
+ t x2 + Cos c2 t Sin[x] x > c2 t ≥ 0
3
c2 t3
+ t x2 + Cos[x] Sin c2 t 0 ≤ x ≤ c2 t
3
0 True

I n [ ] : = Manipulate[Plot3D[%3, {t, 0, 5}, {x, 0, 10},


AxesLabel  {"x", "t", "u(x,t)"}, PlotLabel  "1D Wave Equation Solution",
ColorFunction  "MintColors", PlotRange  All], {c, 0, 2}]
O u t [ ] =

c
24 [Link]

Practical 7 : Solution of the traffic


flow problem with given initial
conditions, and plotting of the
characteristic base curves and
traffic density function .
Problem 1 : Find the trafic density ρ (x, t),
∂ρ ∂ρ
satisfying : + x Sinx =
∂t ∂x
1
0 with initial conditionρ (x, 0) = ρ0 (x) = 1 + .
2
1+x .

Characteristic base curve or IVP :)

I n [ ] : = Charbase = DSolve[{D[x[t], t]  x[t] Sin[t], x[0]  x0}, x[t], t]


O u t [ ] =

x[t]  1-Cos[t] x0

I n [ ] : = (*Along the characteristic base curves,


the function ρ(x(t),t) is conserved an hence we take:ρ(x(t),t)=ρ(x(0),0)=ρ(x(0))*)
Solvex[t]  1-Cos[t] x0, x0
O u t [ ] =

x0  -1+Cos[t] x[t]


[Link] 25

I n [ ] : = x0 = -1+Cos[t] x[t];
1
ρ0[x_] = 1 + ;
1 + x2
(*Solution of the problem*)
ρ = ρ0[x0]
O u t [ ] =
1
1+
1 + -2+2 Cos[t] x[t]2

I n [ ] : = (*Plot of Solution curve*)


Plot3D[1 + 1 / (1 + Exp[- 2 + 2 Cos[t]] x ^ 2), {x, 0, 5},
{t, 0, 5}, PlotLabel  "Characteristic base curve for x0 = 1",
AxesLabel  {"x", "t", "ρ"}, ColorFunction  "Rainbow"]
O u t [ ] =
26 [Link]

I n [ ] : = (*Plot of Characteristic Base Curve*)


Plot[Evaluate[Table[x0 Exp[1 - Cos[t]], {x0, {0.5, 1, 2, 3, 4}}]], {t, 0, 10},
PlotLegends  Placed[{"x0=0.5", "x0=1", "x0=2", "x0=3", "x0=4"}, Right],
PlotLabel  "Family of Characteristic Base Curves",
AxesLabel  {"t", "x(t)"}, PlotStyle  Thick]
O u t [ ] =

Family of Characteristic Base Curves


x(t)

30

25
x0=0.5

20 x0=1
x0=2
15
x0=3
10 x0=4

t
2 4 6 8 10

Problem 2 : Find the trafic density ρ (x, t),


∂ρ ∂ρ
satisfying : + et =
∂t ∂x
2 ρ with initial condition ρ0 (x) = 1 + sin2 x.

Characteristic base curve or IVP :)

I n [ ] : = Charbase1 = DSolve[{D[x[t], t]  Exp[t], x[0]  x0}, x[t], t]


O u t [ ] =

x[t]  - 1 + t + x0

I n [ ] : = (*Along the characteristic base curves,


the function ρ(x(t),t) is conserved an hence we take:ρ(x(t),t)=ρ(x(0),0)=ρ(x(0))*)
Solvex[t]  - 1 + t + x0, x0
O u t [ ] =

x0  1 - t + x[t]

I n [ ] : = Charbase2 = DSolveD[ρ[t], t]  2 ρ[t], ρ[0]  1 + Sin2 [x0], ρ[t], t


O u t [ ] =

ρ[t]  2 t 1 + Sin2 [x0]


[Link] 27

I n [ ] : = (*Solution of the problem*)


ρ = ρ[t] /. Charbase2 /. x0  1 - t + x[t]
O u t [ ] =

2 t 1 + Sin2 1 - t + x[t]

I n [ ] : = (*Plot of solution*)
Plot3D[Exp[2 t] (1 + Sin[x - Exp[t] + 1] ^ 2),
{x, - 5, 5}, {t, - 2, 2}, AxesLabel  {"x", "t", "ρ(x,t)"},
PlotLabel  "Traffic density ρ(x,t)", ColorFunction  "Mint"]
O u t [ ] =

I n [ ] : = (*Plot of Characteristic base curve*)


Plot[Evaluate @ Table[x0 + Exp[t] - 1, {x0, - 4, 4, 1}], {t, - 2, 2},
PlotRange  All, PlotStyle  Table[ColorData["Rainbow"][k / 9], {k, 0, 8}],
AxesLabel  {"t", "x"}, PlotLabel  "Characteristic base curves"]
O u t [ ] =
Characteristic base curves
x

10

t
-2 -1 1 2

-5

You might also like