0% found this document useful (0 votes)
81 views43 pages

PDE PRACTICALS Mathematica

Uploaded by

28 Shivani
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)
81 views43 pages

PDE PRACTICALS Mathematica

Uploaded by

28 Shivani
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
You are on page 1/ 43

RAJDHANI COLLEGE (UNIVERSITY OF DELHI)

SHIVANI
7347
22055563007
BSC.(H) MATHEMATICS 5TH SEMESTER
PRACTICALS : PARTIAL DIFFERENTIAL EQUATIONS

SYLLABUS:

1. General solution of 1st and 2nd order PDEs.

2. Solution and plotting of Cauchy problem for 1st order PDEs.

3. Plotting the characteristics for the 1st order PDEs.

4. Solution of vibrating string problem using D’Alembert formula with initial conditions.

5. Solution of heat equation Ut = k Uxx with initial conditions.

6. Solution of one-dimensional wave equation with initial conditions:


i) u(x,0) = f(x), Ut(x,0) = g(x), x belongs to R , t>0
ii) u(x,0) = f(x), Ut(x,0) = g(x), u(0,t) =0, x belongs to R , t>0
iii) u(x,0) = f(x), Ut(x,0) = g(x), Ux(0,t) =0, x belongs to R , t>0

7. Solution of traffic flow problem with given initial conditions , and plotting of the
characteristic base curves and the traffic density function .
PRACTICAL - 1
General solution of first and second order PDE.
In[27]:= eqn1 = x D[u[x, y], x] + y D[u[x, y], y]  0;
DSolve[eqn1, u[x, y], {x, y}]
Out[28]=
y
u[x, y]  1  
x

In[29]:= eqn6 = 2 * D[u[x, y], x] + 3 * D[u[x, y], y] + u[x, y]  0;


DSolve[eqn6, u[x, y], {x, y}]
Out[30]=
3x
u[x, y]  -x/2 1 - + y
2

In[31]:= eqn9 = x D[u[x, y], x] + y D[u[x, y], y]  3 * u[x, y];


DSolve[eqn9, u[x, y], {x, y}]
Out[32]=
y
u[x, y]  x3 1  
x

In[33]:= eqn3 = D[u[x, y], {y, 2}] + u[x, y]  0;


DSolve[eqn3, u[x, y], {x, y}]
Out[34]=
{{u[x, y]  Cos[y] 1 [x] + Sin[y] 2 [x]}}

In[35]:= eqn5 = D[u[x, y], {x, 2}] - D[u[x, y], {y, 2}]  0;
DSolve[eqn5, u[x, y], {x, y}]
Out[36]=
{{u[x, y]  1 [-x + y] + 2 [x + y]}}

In[37]:= eqn7 = d[u[x, y], {x, 2}] + D[u[x, y], {y, 2}]  6 * x + 2;
DSolve[eqn7, u[x, y], {x, y}]
Out[38]=
u[x,y] 1
Solve  K[2]2  (y + 2 [x])2 ,
1 K[2]
1 [x] + 2 ∫1 (2 + 6 x - d[K[1], {x, 2}])  K[1]

{u[x, y]}

In[39]:= ClearAll[x, y, u]

In[40]:= eqn4 = D[u[x, y], {x, 2}] - 4 D[u[x, y], x, y] + 3 D[u[x, y], {y, 2}]  0;
DSolve[eqn4, u[x, y], {x, y}]
Out[41]=
{{u[x, y]  1 [3 x + y] + 2 [x + y]}}

In[42]:= eqn8 = D[u[x, t], {t, 2}]  4 D[u[x, t], {x, 2}];
DSolve[eqn8, u[x, t], {x, t}]
Out[43]=
x x
u[x, t]  1 t -  + 2 t + 
2 2
PRACTICAL - 2
To obtain the solution of the Cauchy problem for 1st order PDEs
and to plot them

Q1. Ux-Uy = 1 , u[x,0]=x^2


In[44]:= eqn1 = D[u[x, y], x] - D[u[x, y], y]  1;
DSolve[eqn1, u[x, y], {x, y}]
Out[45]=
{{u[x, y]  x + 1 [x + y]}}

In[46]:= IVP = {u[x, 0]  x ^ 2};


sol1 = DSolve[{eqn1, IVP}, u[x, y], {x, y}]
Out[47]=
u[x, y]  x2 - y + 2 x y + y2 

In[48]:= Plot3D[x ^ 2 - y + 2 x y + y ^ 2, {x, -3, 3}, {y, -3, 3}]


Out[48]=

Que2. y Ux- 2xy Uy = 2xu , u[0,y]=y^3

In[51]:= pde2 = y D[u[x, y], x] - 2 x y D[u[x, y], y]  2 x u[x, y];


sol2 = DSolve[pde2, u[x, y], {x, y}]
Out[52]=
1 x2 + y
u[x, y]  
y

In[53]:= IVP = u[0, y]  y ^ 3;


sol2 = DSolve[{pde2, IVP}, u[x, y], {x, y}]
Out[54]=
4
x2 + y
u[x, y]  
y
2 7347_prac_2[1].nb

4
x2 + y
In[55]:= Plot3D , {x, -4, 4}, {y, -4, 4}
y
Out[55]=

In[56]:= ClearAll[x, y, u]

Que3. Ux + Uy = U^2 , u[x,-x]=1

In[57]:= pde3 = D[u[x, y], x] + D[u[x, y], y]  u[x, y] ^ 2;


sol3 = DSolve[pde3, u[x, y], {x, y}]
Out[58]=
1
u[x, y]  
-x - 1 [-x + y]

In[59]:= IVP = u[x, -x]  1;


sol3 = DSolve[{pde3, IVP}, u[x, y], {x, y}]
Out[60]=
2
u[x, y]  - 
-2 + x + y
7347_prac_2[1].nb 3

2
In[61]:= Plot3D- , {x, -1, 1}, {y, -1, 1}
-2 + x + y
Out[61]=

In[62]:= ClearAll[x, y, u]

Que4. Ux +Uy = u^2 , u[x,0] = tanh[x]

In[63]:= pde4 = D[u[x, y], x] + D[u[x, y], y]  u[x, y] ^ 2;


sol4 = DSolve[pde4, u[x, y], {x, y}]
Out[64]=
1
u[x, y]  
-x - 1 [-x + y]

In[65]:= IVP = u[x, 0]  Tanh[x];


sol4 = DSolve[{pde4, IVP}, u[x, y], {x, y}]
Out[66]=
1
u[x, y]  
-y + Coth[x - y]
4 7347_prac_2[1].nb

1
In[67]:= Plot3D , {x, -1, 1}, {y, -1, 1}
-y + Coth[x - y]
Out[67]=

In[68]:= ClearAll[x, y, u]

Que5. y Ux - 2xy Uy = 12xy , u[0,y]=y^3

In[69]:= pde5 = y D[u[x, y], x] - 2 x y D[u[x, y], y]  12 x y;


sol5 = DSolve[pde5, u[x, y], {x, y}]
Out[70]=
u[x, y]  6 x2 + 1 x2 + y

In[71]:= IVP = u[0, y]  y ^ 3;


sol5 = DSolve[{pde5, IVP}, u[x, y], {x, y}]
Out[72]=
u[x, y]  6 x2 + x6 + 3 x4 y + 3 x2 y2 + y3 
7347_prac_2[1].nb 5

In[73]:= Plot3D6 x2 + x6 + 3 x4 y + 3 x2 y2 + y3 , {x, -3, 3}, {y, -3, 3}


Out[73]=

In[74]:= ClearAll[x, y, u]

Que6. u(x+y)Ux + u(x-y)Uy = x^2 + y^2 , u[x,2x]=0

In[75]:= pde6 = u[x, y] * (x + y) D[u[x, y], x] + u[x, y] * (x - y) D[u[x, y], y]  x ^ 2 + y ^ 2;


sol6 = DSolve[pde6, u[x, y], {x, y}]
Out[76]=

u[x, y]  - 2 x y + 1 Log- -x2 + 2 x y + y2  ,

u[x, y]  2 x y + 1 Log- -x2 + 2 x y + y2  ,

1
u[x, y]  - 2 x y + 1  Log-x2 + 2 x y + y2  ,
2
1
u[x, y]  2 x y + 1  Log-x2 + 2 x y + y2  
2

In[77]:= IVP = u[x, 2 x]  0;


sol6 = DSolve[{pde6, IVP}, u[x, y], {x, y}]
Out[78]=

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

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
6 7347_prac_2[1].nb

2 2
In[79]:= Plot3D- 2 x2 + 3 x y - 2 y 2 , 2 x2 + 3 x y - 2 y2 , {x, -3, 3}, {y, -10, 10}
7 7
Out[79]=

In[80]:= ClearAll[x, y, u]

Que7. x Ux+yUy= xe^-u , u=0,y=x^2

In[81]:= pde7 = x * D[u[x, y], x] + y * D[u[x, y], y]  x * Exp[-u[x, y]];

In[82]:= sol7 = DSolve[pde7, u[x, y], {x, y}]


Out[82]=
y
u[x, y]  Logx + 1  
x

In[83]:= IVP = u[x, x ^ 2]  0;


sol7 = DSolve[{pde7, IVP}, u[x, y], {x, y}]
Out[84]=
y
u[x, y]  Log1 + x - 
x
y
In[88]:= PLot3DLog1 + x - , {x, 0, 3}, {y, 0, 3}
x
Out[88]=
y
PLot3DLog1 + x - , {x, 0, 3}, {y, 0, 3}
x
PRACTICAL - 3
Plotting the characteristics for the first order PDE.

Q1. Ux - Uy = 1
Characteristic eqn : dx/1 = dy/-1 = du/1
In[107]:=
DSolve[u '[x]  1, u[x], x]
Out[107]=
{{u[x]  x + 1 }}

In[108]:=
DSolve[u '[y]  -1, u[y], y]
Out[108]=
{{u[y]  -y + 1 }}

In[109]:=
g1 = Plot3D[{x, x - 1, x + 1}, {x, -3, 3}, {y, -3, 3}]
g2 = Plot3D[{-y, -y + 1, -y - 1}, {x, -3, 3}, {y, -3, 3}]
Out[109]=

Out[110]=
2 Shivani_7347_prac-_3[1].nb

In[111]:=
Show[g1, g2]
Out[111]=

In[112]:=
ClearAll[x, y, u]

Q2. UUx + Uy=1


Characteristic eqn : dx/u = dy/1 = du/1
In[113]:=
DSolve[u '[y]  1, u[y], y]
Out[113]=
{{u[y]  y + 1 }}

In[114]:=
DSolve[u[x] * u '[x]  1, u[x], x]
Out[114]=

u[x]  - 2 x + 1 , u[x]  2 x + 1 
Shivani_7347_prac-_3[1].nb 3

In[115]:=
g1 = Plot3D[{y, y + 1, y - 1}, {x, -3, 3}, {y, -3, 3}]
g2 = Plot3D- 2 x, - 2 x+1, - 2 x - 1 , {x, -3, 3}, {y, -3, 3}
g3 = Plot3D 2 x, 2 x+1, 2 x - 1 , {x, -3, 3}, {y, -3, 3}
Out[115]=

Out[116]=

Out[117]=
4 Shivani_7347_prac-_3[1].nb

In[118]:=
Show[g1, g2, g3]
Out[118]=

Q3. Ux + Uy = 0
Characteristic eqn : dx/1 = dy/1 = du/0
In[119]:=
ClearAll[x, y, u]
In[120]:=
DSolve[u '[x]  0, u[x], x]
Out[120]=
{{u[x]  1 }}

In[121]:=
DSolve[y '[x]  1, y[x], x]
Out[121]=
{{y[x]  x + 1 }}
Shivani_7347_prac-_3[1].nb 5

In[122]:=
g1 = Plot3D[{-1, 0, 1}, {x, -3, 3}, {y, -3, 3}]
g2 = Plot3D[{x, x + 1, x - 1}, {x, -3, 3}, {y, -3,
3}]

Out[122]=

Out[123]=
6 Shivani_7347_prac-_3[1].nb

In[124]:=
Show[g1, g2]
Out[124]=

Q4. (U-y)Ux + y Uy = x+y


Characteristic eqn : dx/u-y = dy/y = du/x+y
In[125]:=
ClearAll[x, y,
u]

In[126]:=
DSolve[u '[x]  (x + y) / (u[x] - y), u[x], x]
Out[126]=

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

In[127]:=

p1 = Plot3Dy - x2 + 2 x y + y 2 - 2 , y - x2 + 2 x y + y 2 - 2 , y - x2 + 2 x y + y2 + 2 ,

{x, -3, 3}, {y, -3, 3}


Out[127]=
Shivani_7347_prac-_3[1].nb 7

In[129]:=

p2 = Plot3Dy + x2 + 2 x y + y 2 - 2 , y + x2 + 2 x y + y 2 - 2 , y + x2 + 2 x y + y2 + 2 ,

{x, -3, 3}, {y, -3, 3}


Out[129]=

In[130]:=
DSolve[y * t '[y]  t[y], t[y], y]
Out[130]=
{{t[y]  y 1 }}

In[131]:=
p3 = Plot3D[{-x, y - x, -y - x}, {x, -3, 3}, {y, -3, 3}]
Out[131]=
8 Shivani_7347_prac-_3[1].nb

In[132]:=
Show[p1, p2, p3]
Out[132]=

Que5. y Ux + x Uy = u
Characteristic eqn : dx/y = dy/x = du/u
In[133]:=
ClearAll[x, y, u]
In[134]:=
DSolve[y '[x]  x / y[x], y[x], x]
Out[134]=

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

In[135]:=
DSolve[u '[v]  u[v] / v, u[v], v]
Out[135]=
{{u[v]  v 1 }}
Shivani_7347_prac-_3[1].nb 9

In[136]:=

a1 = Plot3D- x2 , - x2 + 2 , - x2 - 2 , {x, -3, 3}, {y, -3, 3}


Out[136]=

In[137]:=

a2 = Plot3D x2 , x2 + 2 , x2 - 2 , {x, -3, 3}, {y, -3, 3}


Out[137]=
10 Shivani_7347_prac-_3[1].nb

In[138]:=
a3 = Plot3D[{0, x + y, -x - y}, {x, -3, 3}, {y, -3, 3}]
Out[138]=

In[139]:=
Show[a1, a2, a3]
Out[139]=
PRACTICAL - 4
Solution of vibrating string problem using D’Alembert formula with initial
condition

Q1. Utt = Uxx , -∞<x<∞


u(x,0) = Sinx , -∞<x<∞
Ut(x,0) = 0 , -∞<x<∞
In[204]:=
c = 1;
f[x_] := Sin[x]
g[x_] := 0
1 1 x+c t
u[x_, t_] := * (f[x + c t] + f[x - c t]) + * g[s]  s
2 2c x-c t

Print[u[x, t]]
1
(-Sin[t - x] + Sin[t + x])
2
In[209]:=
h0 = Plot[Evaluate[u[x, 0]], {x, -6, 6}]
Out[209]=

1.0

0.5

-6 -4 -2 2 4 6

-0.5

-1.0

In[210]:=
h1 = Plot[Evaluate[u[x, 1]], {x, -6, 6}]
Out[210]=
0.6

0.4

0.2

-6 -4 -2 2 4 6

-0.2

-0.4

-0.6
2 SHIVANI_7347_PRAC_-_4[1].nb

In[211]:=
h2 = Plot[Evaluate[u[x, 2]], {x, -6, 6}]
Out[211]=

0.4

0.2

-6 -4 -2 2 4 6

-0.2

-0.4

In[212]:=
Show[h0, h1, h2, PlotStyle  {Red}]
Out[212]=

1.0

0.5

-6 -4 -2 2 4 6

-0.5

-1.0

In[213]:=
Plot3D[u[x, t], {x, -3, 3}, {t, 0, 3}]
Out[213]=

Q2. Utt = 4Uxx , -∞<x<∞ , t>0


SHIVANI_7347_PRAC_-_4[1].nb 3

u(x,0) = - x^2 Sinx ,-∞<x<∞


Ut(x,0) = 0 , -∞<x<∞
In[214]:=
c = 2;
f[x_] := -x^2 Sin[x]
g[x_] := 0
1 1 x+c t
u[x_, t_] := * (f[x + c t] + f[x - c t]) + * g[s]  s
2 2c x-c t

Print[u[x, t]]
1 2 2
--(-2 t+x) Sin[2 t - x] + -(2 t+x) Sin[2 t + x]
2
In[219]:=
h0 = Plot[Evaluate[u[x, 0]], {x, -6, 6}]
Out[219]=

0.04

0.02

-6 -4 -2 2 4 6

-0.02

-0.04

In[220]:=
h1 = Plot[Evaluate[u[x, 1]], {x, -6, 6}]
Out[220]=

0.2

0.1

-6 -4 -2 2 4 6

-0.1

-0.2
4 SHIVANI_7347_PRAC_-_4[1].nb

In[221]:=
h3 = Plot[Evaluate[u[x, 2]], {x, -6, 6}]
Out[221]=

0.2

0.1

-6 -4 -2 2 4 6

-0.1

-0.2

In[222]:=
Show[h0, h1, h2, PlotStyle  {Red}]
Out[222]=

0.04

0.02

-6 -4 -2 2 4 6

-0.02

-0.04

In[223]:=
Plot3D[u[x, t], {x, -3, 3}, {t, 0, 3}]
Out[223]=

Q3. Utt = 2Uxx


u(x,0) = 0 , x< -1
SHIVANI_7347_PRAC_-_4[1].nb 5

= 1, -1≤x≤1
= 0 , x>1
ut(x,0) = Sinx
In[224]:=

c = 2;
f[x_] := Piecewise[{{0, x < -1}, {1, -1 ≤ x ≤ 1}, {0, x > 1}}]
g[x_] := Sin[x]
1 1 x+c t
u[x_, t_] := * (f[x + c t] + f[x - c t]) + * g[s]  s
2 2c x-c t

Print[u[x, t]]

1 0 - 2 t + x < -1 0 2 t + x < -1 Sin 2 t Sin[x]


1 -1 ≤ - 2 t+x≤1 + 1 -1 ≤ 2 t+x≤1 +
2 2
0 True 0 True
In[229]:=
h0 = Plot[Evaluate[u[x, 0]], {x, -6, 6}, PlotLegends  "Wave at t=0"]
Out[229]=

1.0

0.8

0.6

Wave at t=0
0.4

0.2

-6 -4 -2 2 4 6

In[230]:=
h1 = Plot[Evaluate[u[x, 1]], {x, -6, 6}, PlotLegends  "Wave at t=1", PlotStyle  Red]
Out[230]=

1.0

0.5

Wave at t=1

-6 -4 -2 2 4 6

-0.5
6 SHIVANI_7347_PRAC_-_4[1].nb

In[231]:=
h2 = Plot[Evaluate[u[x, 2]], {x, -6, 6}, PlotLegends  "Wave at t=2", PlotStyle  Green]
Out[231]=

0.6

0.4

Wave at t=2
0.2

-6 -4 -2 2 4 6

-0.2

In[232]:=
Show[h0, h1, h2]
Out[232]=

1.0

0.8

0.6
Wave at t=0
Wave at t=1
0.4 Wave at t=2

0.2

-6 -4 -2 2 4 6

Q4.Utt = 2Uxx
u(x,0) = Sinx
Ut(x,0) = Cosx
In[233]:=

c = 2;
f[x_] := Sin[x]
g[x_] := Cos[x]
In[236]:=
1 1 x+c t
u[x_, t_] := * (f[x + c t] + f[x - c t]) + * g[s]  s
2 2c x-c t

Print[u[x, t]]
Cos[x] Sin 2 t 1
+ -Sin 2 t - x + Sin 2 t + x
2 2

Cos[x] Sin 2 t 1
+ -Sin 2 t - x + Sin 2 t + x
2 2
SHIVANI_7347_PRAC_-_4[1].nb 7

In[238]:=
h0 = Plot[Evaluate[u[x, 0]], {x, -6, 6}, PlotLegends  "Wave at t=0"]
Out[238]=

1.0

0.5

-6 -4 -2 2 4 6
Wave at t=0

-0.5

-1.0

In[239]:=
h1 = Plot[Evaluate[u[x, 1]], {x, -6, 6}, PlotLegends  "Wave at t=1", PlotStyle  Red]
Out[239]=

0.6

0.4

0.2

-6 -4 -2 2 4 6
Wave at t=1

-0.2

-0.4

-0.6

In[240]:=
h2 = Plot[Evaluate[u[x, 2]], {x, -6, 6}, PlotLegends  "Wave at t=2", PlotStyle  Green]
Out[240]=

1.0

0.5

-6 -4 -2 2 4 6
Wave at t=2

-0.5

-1.0
8 SHIVANI_7347_PRAC_-_4[1].nb

In[241]:=
Show[h0, h1, h2]
Out[241]=

1.0

0.5

Wave at t=0
Wave at t=1
-6 -4 -2 2 4 6
Wave at t=2

-0.5

-1.0

Q5. Utt = πUxx


u(x,0) = 0
ut(x,0) = - x^2
In[242]:=
c = √ π;
f[x_] := 0
g[x_] := -x^2
In[245]:=
1 1 x+c t
u[x_, t_] := * (f[x + c t] + f[x - c t]) + * g[s]  s
2 2c x-c t

Print[u[x, t]]
1
Erf π t - x + Erf π t + x
4
In[247]:=
h0 = Plot[Evaluate[u[x, 0]], {x, -6, 6}, PlotLegends  "Wave at t=0", PlotStyle  Blue]
Out[247]=

1.0

0.5

-6 -4 -2 2 4 6
Wave at t=0

-0.5

-1.0
SHIVANI_7347_PRAC_-_4[1].nb 9

In[248]:=
h1 = Plot[Evaluate[u[x, 1]], {x, -6, 6}, PlotLegends  "Wave at t=1", PlotStyle  Red]
Out[248]=

0.5

0.4

0.3

Wave at t=1
0.2

0.1

-6 -4 -2 2 4 6

In[249]:=
h2 = Plot[Evaluate[u[x, 2]], {x, -6, 6}, PlotLegends  "Wave at t=2", PlotStyle  Green]
Out[249]=

0.5

0.4

0.3

Wave at t=2
0.2

0.1

-6 -4 -2 2 4 6

In[250]:=
Show[h0, h1, h2]
Out[250]=

1.0

0.5

Wave at t=0
Wave at t=1
-6 -4 -2 2 4 6
Wave at t=2

-0.5

-1.0
PRACTICAL - 5
Solution of the heat equation Ut = KUxx with the given
initial condition.
Que1. Ut - kUxx = 0 , 0 < x < 5 , t > 0 , u (x, 0) = 0, u (0, t) = sin t , u (5, t) = 0 , k = 1
I n [ ] : = K = 1;
pde = D[u[x, t], t] - k D[u[x, t], {x, 2}]  0;
DSolve[{pde, u[x, 0]  0, u[0, t]  Sin[t], u[5, t]  0}, u[x, t], {x, t}]
O u t [ ] =
1
u[x, t]  - (-5 + x) Sin[t] +
5
1
- π2 t 1[1]2 1
∞ 50  25 π2 1[1]2 - 50 π2 1[1]2 Cos[t] - 1250 Sin[t] Sin π x 1[1]
5
 
1[1]=1 625 π 1[1] + π5 1[1]5

I n [ ] : = k = 1;
0 < x < 5;
pde = D[u[x, t], t]  k D[u[x, t], {x, 2}];
s=
NDSolve[{pde, u[x, 0]  0, u[0, t]  Sin[t], u[5, t]  0}, u[x, t], {x, 0, 5}, {t, 0, 5}]
Plot3D[Evaluate[u[x, t] /. s], {x, 0, 5}, {t, 0, 5}]
O u t [ ] =

Domain: {{0., 5.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

O u t [ ] =

Que2. u(x,0)=Sin x , u(0,t)=0 , u(π,t)=0 , k=1


I n [ ] : = ClearAll[x, y, u, t]
2 SHIVANI_PRAC-_5[1].nb

I n [ ] : = k = 1;
pde2 = D[u[x, t], t]  k * D[u[x, t], {x, 2}];
sol2 = NDSolve[
{pde2, u[x, 0]  Sin[x], u[0, t]  0, u[π, t]  0}, u[x, t], {x, 0, π}, {t, 0, 5}]
Plot3D[Evaluate[u[x, t] /. sol], {x, -5, 5}, {t, 0, 5}]
O u t [ ] =

Domain: {{0., 3.14}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol2], {x, 0, 5}, {t, 0, 5}]


O u t [ ] =

Que3. u(x,0)=Tanh x , u(0,t)=t , u(10,t)=0 , k=1


I n [ ] : = k = 1;
pde3 = D[u[x, t], t]  k * D[u[x, t], {x, 2}];
sol3 = NDSolve[
{pde3, u[x, 0]  Tanh[x], u[0, t]  t, u[10, t]  0}, u[x, t], {x, 0, π}, {t, 0, 5}]
NDSolve: Warning: boundary and initial conditions are inconsistent.
O u t [ ] =

Domain: {{0., 10.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar
SHIVANI_PRAC-_5[1].nb 3

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol3], {x, 0, 5}, {t, 0, 5}]


O u t [ ] =

Que4. u(x,0)=Sin π x , u(0,t)=t , u(1,t)=t^2 , k=4


I n [ ] : = k = 4;
pde4 = D[u[x, t], t]  k * D[u[x, t], {x, 2}];
sol4 = NDSolve[
{pde4, u[x, 0]  Sin[π * x], u[0, t]  t, u[1, t]  t ^ 2}, u[x, t], {x, 0, 1}, {t, 0, 5}]
O u t [ ] =

Domain: {{0., 1.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol4], {x, 0, 5}, {t, 0, 5}]


O u t [ ] =
PRACTICAL - 6
SOLUTION OF WAVE EQUATION Utt - c 2Uxx = 0

Q1. f(x) = Sinx , g(x) = x^2 , c=1


I n [ ] : = c=1
pde1 = D[u[x, t], {t, 2}] - c2 * D[u[x, t], {x, 2}]  0 ;
sol1 = DSolvepde1, u[x, 0]  Sin[x], Derivative[0, 1][u][x, 0]  x2 , u[x, t], {x, t}
O u t [ ] =
1
O u t [ ] =
1 1 1 1
- (-t + x)3 + (t + x)3  + (-Sin[t - x] + Sin[t + x]) t ≥ 0
u[x, t]  2 3 3 2 
Indeterminate True

I n [ ] : = NDSolvepde1, u[x, 0]  Sin[x], Derivative[0, 1][u][x, 0]  x2 ,


u[x, t], {x, 0, 5}, {t, 0, 5}

NDSolve: Warning: an insufficient number of boundary conditions have been specified for the direction of independent
variable x. Artificial boundary effects may be present in the solution.
O u t [ ] =

Domain: {{0., 5.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol1], {x, 0, 5}, {t, 0, 5}]


O u t [ ] =

Q2. f(x) = 10x 4 , g(x) = 0 , u(0,t) = 0 , c = 2

I n [ ] : = ClearAll[x, y, u, t]
2 Shivani_7347_prac_-_6[1].nb

In[141]:=
c = 2;
pde2 = D[u[x, t], {t, 2}] - c2 * D[u[x, t], {x, 2}]  0 ;
sol2 = DSolvepde2, u[x, 0]  10 * x4 , Derivative[0, 1][u][x, 0]  0, u[x, t], {x, t}

Out[143]=
1
10 (-2 t + x)4 + 10 (2 t + x)4  t ≥ 0
u[x, t]  2 
Indeterminate True

I n [ ] : = NDSolvepde2, u[x, 0]  10 * x4 , Derivative[0, 1][u][x, 0]  0,


u[x, t], {x, -3, 3}, {t, 0, 5}
O u t [ ] =

Domain: {{- 3., 3.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol2], {x, -3, 3}, {t, 0, 5}]


O u t [ ] =

Q3. f(x) = 0 , g(x) = x^3 , u(0,t) = 0, c=3

I n [ ] : = ClearAll[x, y, u, t]

I n [ ] : = c=3
pde3 = D[u[x, t], {t, 2}] - c2 * D[u[x, t], {x, 2}]  0 ;
sol3 = DSolvepde2, u[x, 0]  0, Derivative[0, 1][u][x, 0]  x 3 , u[x, t], {x, t}

O u t [ ] =
3
O u t [ ] =
1 1 1
- (-2 t + x)4 + (2 t + x)4  t ≥ 0
u[x, t]  4 4 4 
Indeterminate True

I n [ ] : = NDSolvepde3, u[x, 0]  0, Derivative[0, 1][u][x, 0]  x3 ,


u[x, t], {x, -5, 5}, {t, 0, 5}
O u t [ ] =

Domain: {{- 5., 5.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar
Shivani_7347_prac_-_6[1].nb 3

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol3], {x, -5, 5}, {t, 0, 5}]


O u t [ ] =

Q4. u(0,t) = 0 , u(1,t) = 0 , f(x) = 10x^2 (1 - x^2) , g(x) =0 , c=1

I n [ ] : = ClearAll[x, y, u, t]

I n [ ] : = c=1
pde4 = D[u[x, t], {t, 2}] - c2 * D[u[x, t], {x, 2}]  0 ;
sol4 = DSolvepde4, u[0, t]  0, u[1, t]  0,
u[x, 0]  10 x2 * 1 - x2 , Derivative[0, 1][u][x, 0]  0, u[x, t], {x, t}

O u t [ ] =
1
O u t [ ] =

u[x, t] 
∞ 480 -1 + (-1)1[1]  - 40 1 + 5 (-1)1[1]  π2 1[1]2  Cos[π t 1[1]] Sin[π x 1[1]]
 
1[1]=1 π5 1[1]5

I n [ ] : = NDSolvepde4, u[0, t]  0, u[1, t]  0, u[x, 0]  10 x2 * 1 - x2 ,


Derivative[0, 1][u][x, 0]  0, u[x, t], {x, 0, 1}, {t, 0, 5}
O u t [ ] =

Domain: {{0., 1.}, {0., 5.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar
4 Shivani_7347_prac_-_6[1].nb

I n [ ] : = Plot3D[Evaluate[u[x, t] /. sol4], {x, 0, 1}, {t, 0, 5}]


O u t [ ] =
PRACTICAL - 7
Solution of traffic flow problem with given initial conditions, and plotting of the
characteristic base curves and the traffic density function.

Q1. Find the traffic density u(x,t) satisfying


∂u
∂t
+ xSint ∂∂ux = 0
1
with the initial condition u(x,0) = 1 +
x2
solution : The characteristic equations are :
dt dx du
= =
1 xsint 0
on taking 1=2 , we get the characteristic base curves

In[88]:= sol1 = DSolve[x '[t]  x[t] * Sin[t], x[t], t]


Out[88]=
x[t]  -Cos[t] 1 

In[89]:= Plot-Cos[t] , 2 -Cos[t] , 5 -Cos[t] , {t, 0, 4}


Out[89]=
14

12

10

1 2 3 4

The traffic density is given by

In[90]:= eqn2 = D[u[x, t], t] + x Sin[t] D[u[x, t], x]  0;


1
sol2 = DSolveeqn2, u[x, 0]  1 + , u[x, t], {x, t}
1 + x2
DSolve: Inverse functions are being used by DSolve, so some solutions may not be found.
Out[91]=
2 2 + 2 Cos[t] x2
u[x, t]  
2 + 2 Cos[t] x2
2 shivani 7347 prac - 7[1].nb

In[92]:= Plot3D[u[x, t] /. sol2, {x, 0, 1}, {t, 0, 4}]


Out[92]=

Q2. find the traffic density u(x,t) satisfying


∂u ∂u
+ =0
∂t ∂x
0 x<0
with the initial condition u(x,0) = 4 x 0 < x < 1,
0 x>1

solution : The characteristic equations are


dt dx du
= =
1 2 0
on taking 1 = 3, we get

In[93]:= ClearAll;

In[94]:= sol2 = DSolve[x '[t]  2, x[t], t]


Out[94]=
{{x[t]  2 t + 1 }}

In[95]:= Plot[{2 t + 1, 2 t + 2, 2 t - 4}, {t, 0, 4}]


Out[95]=

10

1 2 3 4

-2

-4

In[96]:= f[x_] := Piecewise[{{0, x < 0}, {4 x, 0 < x < 1}, {0, x > 1}}];
shivani 7347 prac - 7[1].nb 3

In[97]:= eqn2 = D[u[x, t], t] + 2 * D[u[x, t], x]  0;

In[98]:= sol2 = DSolve[{eqn2, u[x, 0]  f[x]}, u[x, t], {x, t}]


Out[98]=
x
0 -2 t -  < 0
2
u[x, t]  x
-4 (2 t - x) 0 < -2 t -  < 1
2
0 True

In[99]:= Plot3D[u[x, t] /. sol2, {x, -1, 3}, {t, 0, 1}, AxesLabel  Automatic]
Out[99]=

In[100]:=
ClearAll
Out[100]=
ClearAll

In[101]:=
sol3 = DSolve[t '[x]  1 / 2, t[x], x]
Out[101]=
x
t[x]  + 1 
2
In[102]:=
x x x
Plot , + 1, + 2, {x, -3, 3}
2 2 2
Out[102]=

-3 -2 -1 1 2 3

-1

Q3. find the traffic density u(x,t) satisfying


∂u ∂u
+ 2u =0
∂t ∂x
4 shivani 7347 prac - 7[1].nb

1 x<0
with the initial condition u(x,0) = 1 - x 0 < x < 1,
0 x≤1
plotting initial condition
In[103]:=
sol1 = DSolve[u '[t]  0, u[t], t]
Out[103]=
{{u[t]  1 }}

In[104]:=
1
sol2 = DSolvet '[x]  , t[x], x
2c
Out[104]=
x
t[x]  + 1 
2c
In[105]:=
Plot[{x / 2, x / 2 + 1, x / 2 - 1}, {x, -6, 6}]
Out[105]=

-6 -4 -2 2 4 6

-2

-4

In[106]:=
f[x_] := Piecewise[{{1, x < 0}, {1 - x, 0 < x < 1}, {0, x > 1}}];
In[107]:=
Plot[{Piecewise[{{1, x < 0}, {1 - x, 0 < x < 1}, {0, x > 1}}]}, {x, -5, 5}]
Out[107]=

1.0

0.8

0.6

0.4

0.2

-4 -2 2 4

In[108]:=
eqn3 = D[u[x, t], t]  -2 D[u[x, t], x];
shivani 7347 prac - 7[1].nb 5

In[109]:=
sol3 = DSolve[{eqn3, u[x, 0]  f[x]}, u[x, t], {x, t}]
Out[109]=
x
1 -2 t -  < 0
2
u[x, t]  x
1 + 2 t - x 0 < -2 t -  < 1
2
0 True

In[110]:=
Plot3D[u[x, t] /. sol3, {x, -1, 3}, {t, 0, 1}, AxesLabel  Automatic]
Out[110]=
ASSIGNMENT
Q1. Find the general solution of the following partial differential equations
a) Uxx - 4Uxy +3Uyy = 0

In[16]:= DSolve[D[u[x, y], {x, 2}] - 4 D[u[x, y], x, y] + 3 D[u[x, y], {y, 2}]  0, u[x, y], {x, y}]
Out[16]=
{{u[x, y]  1 [3 x + y] + 2 [x + y]}}

b) xUx + yUy = 2u

In[17]:= DSolve[x D[u[x, y], x] + y D[u[x, y], y]  2 u[x, y], u[x, y], {x, y}]
Out[17]=
y
u[x, y]  x2 1  
x

Q2. Obtain the solution of the equation


yUx - 2xyUy - 2xu = 0
with Cauchy data u(0,y) = y 3

In[18]:= DSolve[{y D[u[x, y], x] - 2 x y D[u[x, y], y]  2 x u[x, y], u[0, y]  y ^ 3}, u[x, y], {x, y}]
Out[18]=
4
x2 + y
u[x, y]  
y
4
x2 + y
In[19]:= Plot3D , {x, -5, 5}, {y, -5, 5}
y
Out[19]=

Q3. Plot the characteristic curves for the PDE


Ux - Uy = 1
Characteristic eqn are :
dx dy du
= =
1 -1 1
2 SHIVANI 7347 ASSIGNMENT[1].nb

In[20]:= DSolve[u '[x]  1, u[x], x]


Out[20]=
{{u[x]  x + 1 }}

In[21]:= DSolve[u '[y]  -1, u[y], y]


Out[21]=
{{u[y]  -y + 1 }}

In[22]:= g1 = Plot3D[{x, x - 1, x + 1}, {x, -4, 4}, {y, -4, 4}]


Out[22]=

In[23]:= g2 = Plot3D[{-y, -y + 1, -y - 1}, {x, -4, 4}, {y, -4, 4}]


Out[23]=
SHIVANI 7347 ASSIGNMENT[1].nb 3

In[24]:= Show[g1, g2]


Out[24]=

Q4. Find the solution of the following initial value problem


Ut = Uxx , 0<x<2 , t>0
u(x,0) = x , 0≤x≤2
u(0,t) = 0 , Ux(2,t) = 1 , t≥0

In[25]:= ClearAll[x, y, u, t]
4 SHIVANI 7347 ASSIGNMENT[1].nb

In[26]:= k = 1;
0 < x < 2;
pde1 = D[u[x, t], t]  k D[u[x, t], {x, 2}];
s = NDSolve[{pde1, u[x, 0]  x, u[0, t]  0, Derivative[1, 0][u][2, t]  1},
u[x, t], {x, 0, 2}, {t, 0, 3}]
Plot3D[Evaluate[u[x, t] /. s], {x, 0, 2}, {t, 0, 3}]
Out[29]=

Domain: {{0., 2.}, {0., 3.}}


u[x, t]  InterpolatingFunction [x, t]
Output: scalar

Out[30]=

In[31]:=

You might also like