0% fanden dieses Dokument nützlich (0 Abstimmungen)
8 Ansichten26 Seiten

Du Practicals

Du material

Hochgeladen von

Dev Bahl
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen
0% fanden dieses Dokument nützlich (0 Abstimmungen)
8 Ansichten26 Seiten

Du Practicals

Du material

Hochgeladen von

Dev Bahl
Copyright
© All Rights Reserved
Wir nehmen die Rechte an Inhalten ernst. Wenn Sie vermuten, dass dies Ihr Inhalt ist, beanspruchen Sie ihn hier.
Verfügbare Formate
Als PDF, TXT herunterladen oder online auf Scribd lesen

Pranav Ajith

College Roll Number - 8769


[Link](Hons)Ghawri,
NAME-Akshas Mathematics
Roll- Semester
no-8795,VUniv
University Roll Number - 22025563056
Roll-22025563015
Partial Differential Equation

Practical-01:General solution of first and


second order partial differential equations
● f(x)=Ux(x,y)+Uy(x,y)=0

In[44]:= pde1 = D[u[x, y], x] + x * D[u[x, y], y] ⩵ 0


Out[44]=
x u(0,1) [x, y] + u(1,0) [x, y] ⩵ 0

In[45]:= sol1 = DSolve[pde1, u[x, y], {x, y}]


Out[45]=
x2
u[x, y] → 1 - + y
2

● f(x)=y*Uy(x,y)+x*Ux(x,y)-2xy=0

In[46]:= pde2 = x * D[u[x, y], x] + y * D[u[x, y], y] ⩵ 2 * x * y;


DSolve[pde2, u[x, y], {x, y}]
Out[47]=
y
u[x, y] → x y + 1  
x

● f(x)=t*Ut(x,t)+3x*Ux(x,t)=0

In[48]:= pde3 = 3 * x * D[u[x, t], x] + t * D[u[x, t], t] ⩵ 0;


DSolve[pde3, u[x, t], {x, t}]
Out[49]=
t
u[x, t] → 1  
x1/3
2

● f(x)=x*Uy(x,y)+Ux(x,y)=0

In[50]:= pde4 = D[u[x, y], x] + x * D[u[x, y], y] ⩵ 0;


DSolve[pde4, u[x, y], {x, y}]
Out[51]=
x2
u[x, y] → 1 - + y
2

● f(x)=2*Uy(x,y)+3*Ux(x,y)=0

In[52]:= pde5 = 3 * D[u[x, y], x] + 2 * D[u[x, y], y] ⩵ 0;


DSolve[pde5, u[x, y], {x, y}]
Out[53]=

2x
u[x, y] → 1 - + y
3

● f(x)=Uyy(x,y)+Uxx(x,y)-y*Sin(x)=0 such that u(x,0)=x^2

In[54]:= pde6 = Dux, y, {x, 2} + D[u[x, y], y, y] ⩵ Sin[x] * y


solution = DSolve{pde6}, ux, y, x, y
Out[54]=
u(0,2) [x, y] + u(2,0) [x, y] ⩵ y Sin[x]
Out[55]=
u[x, y] → - y Sin[x] + 1 x - ⅈ y + 2 x + ⅈ y

Practical-02:Solution and plotting of


Cauchy problem for first order PDEs
● f(x)=x*Uy(x,y)+Ux(x,y)=0

In[56]:= pde4 = D[u[x, y], x] + x * D[u[x, y], y] ⩵ 0


DSolve[pde4, u[x, y], {x, y}]
Out[56]=
x u(0,1) [x, y] + u(1,0) [x, y] ⩵ 0
Out[57]=
x2
u[x, y] → 1 - + y
2
3

In[58]:= Plot3D[1, {x, - 5, 5}, {y, - 5, 5}]


Out[58]=

● f(x)=y*Uy(x,y)+x*Ux(x,y)-2xy=0

In[4]:= pde2 = x * D[u[x, y], x] + y * D[u[x, y], y] ⩵ 2 * x * y;


DSolve[pde2, u[x, y], {x, y}]
y
Out[5]= u[x, y] → x y + 1  
x

In[26]:= Plot3Dx * y, x, - 5, 5, y, - 5, 5


Out[26]=
4

● f(x)=y*Uy(x,y)+x*Ux(x,y)-U(x,y)=0

In[29]:= pde21 = x * D[u[x, y], x] + y * Dux, y, y ⩵ ux, y


DSolve[pde21, u[x, y], {x, y}]
Out[29]=
y u(0,1) [x, y] + x u(1,0) [x, y] ⩵ u[x, y]
Out[30]=
y
u[x, y] → x 1  
x

In[31]:= Plot3D[x, {x, - 5, 5}, {y, - 5, 5}]


Out[31]=

● f(x)=y*Uy(x,y)+x*Ux(x,y)-U(x,y)-1=0

In[36]:= pde22 = x * D[u[x, y], x] + y * D[u[x, y], y] ⩵ u[x, y] + 1


DSolve[pde22, u[x, y], {x, y}]
Out[36]=
y u(0,1) [x, y] + x u(1,0) [x, y] ⩵ 1 + u[x, y]
Out[37]=
y
u[x, y] → - 1 + x 1  
x
5

In[38]:= Plot3D[- 1 + x, {x, - 5, 5}, {y, - 5, 5}]


Out[38]=

Practical-03:Plotting the characteristics for


the first order partial differential equations
● f(x)=y*Uy(x,y)+x*Ux(x,y)-U(x,y)-1=0

In[36]:= pde22 = x * D[u[x, y], x] + y * D[u[x, y], y] ⩵ u[x, y] + 1


DSolve[pde22, u[x, y], {x, y}]
Out[36]=

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


Out[37]=
y
u[x, y] → - 1 + x 1  
x
6

In[47]:= ContourPlot[y / x, {x, - 5, 5}, {y, - 5, 5}]


Out[47]=

-2

-4

-4 -2 0 2 4

● f(x)=x*Uy(x,y)+Ux(x,y)=0

In[19]:= pde4 = D[u[x, y], x] + x * D[u[x, y], y] ⩵ 0


DSolve[pde4, u[x, y], {x, y}]
Out[19]=
x u(0,1) [x, y] + u(1,0) [x, y] ⩵ 0
Out[20]=
x2
u[x, y] → 1 - + y
2
7

In[48]:= ContourPlot[y - (x ^ 2) / 2, {x, - 5, 5}, {y, - 5, 5}]


Out[48]=

-2

-4

-4 -2 0 2 4

● f(x)=2*Uy(x,y)+3*Ux(x,y)=0

In[12]:= pde5 = 3 * D[u[x, y], x] + 2 * D[u[x, y], y] ⩵ 0;


DSolve[pde5, u[x, y], {x, y}]
Out[13]=
2x
u[x, y] → 1 - + y
3
8

In[49]:= ContourPloty (- 2 * x) / 3, {x, - 5, 5}, {y, - 5, 5}


Out[49]=

-2

-4

-4 -2 0 2 4

● f(x)=t*Ut(x,t)+3x*Ux(x,t)=0

In[8]:= pde3 = 3 * x * D[u[x, t], x] + t * D[u[x, t], t] ⩵ 0;


DSolve[pde3, u[x, t], {x, t}]
t
Out[9]= u[x, t] → 1  
x1/3
9

In[51]:= ContourPlot[t / (x ^ (1 / 3)), {x, 0, 10}, {t, 0, 10}]


Out[51]=
10

0
0 2 4 6 8 10

● f(x)=y*Uy(x,y)+x*Ux(x,y)-2xy=0

In[4]:= pde2 = x * D[u[x, y], x] + y * D[u[x, y], y] ⩵ 2 * x * y;


DSolve[pde2, u[x, y], {x, y}]
y
Out[5]= u[x, y] → x y + 1  
x
10

In[54]:= ContourPlot[y / x, {x, - 10, 10}, {y, - 10, 10}]


Out[54]=
10

-5

-10
-10 -5 0 5 10

Practical-04:Solution of vibrating string


problem using D’Alembert formula with
initial conditions

◼ Ques.1: -Utt-c^(2)*Uxx=0; u(x,0)=Sin(x ); Ut(x,0)=x^2

In[74]:= f[x_] := Sin[x]


g[x_] := x ^ 2
z[x_ , t_ , c_] := (1 / 2)[f[x + c * t] + f[x - c * t]] + (1 / (2 * c))[Integrate[g[m], {m, x - c * t, x + c * t}]]

In[77]:= z[x, t, c]
Out[77]=
1 1 1 3 1 3
- Sinc t - x + Sinc t + x + - - c t + x + c t + x 
2 2c 3 3
11

◼ Ques.2: -Utt-c^(2)*Uxx=0; u(x,0)=x^3; Ut(x,0)=x^2

In[4]:= f[x_] := x ^ 3
g[x_] := x ^ 2
z[x_ , t_ , c_] := (1 / 2)[f[x + c * t] + f[x - c * t]] + (1 / (2 * c))[Integrate[g[m], {m, x - c * t, x + c * t}]]

In[7]:= z[x, t, c]
1 3 3 1 1 3 1 3
Out[7]= - c t + x + c t + x + - - c t + x + c t + x 
2 2c 3 3

◼ Ques.3: -Utt-c^(2)*Uxx=0; u(x,0)=Cos(x); Ut(x,0)=e^(-1)

In[8]:= f[x_] := Cos[x]


g[x_] := Exp[- 1]
z[x_ , t_ , c_] := (1 / 2)[f[x + c * t] + f[x - c * t]] + (1 / (2 * c))[Integrate[g[m], {m, x - c * t, x + c * t}]]

In[11]:= z[x, t, c]
Out[11]=
1 1 2ct
Cosc t - x + Cosc t + x +  
2 2c ⅇ

◼ Ques.4: -Utt-c^(2)*Uxx=0; u(x,0)=Sin^2(x); Ut(x,0)=e^(-x^2)

In[12]:= f[x_] := Sin[x] ^ (2)


g[x_] := Exp[- x ^ 2]
z[x_ , t_ , c_] := (1 / 2)[f[x + c * t] + f[x - c * t]] + (1 / (2 * c))[Integrate[g[m], {m, x - c * t, x + c * t}]]

In[15]:= z[x, t, c]
Out[15]=
1 2 2 1 1
Sinc t - x + Sinc t + x +  π Erfc t - x + Erfc t + x
2 2c 2
12

Practical-05: Solution of heat equation


Ut=k*Uxx with initial conditions

◼ Ques.1: Ut-5*Uxx=0; u(x,0)=1-Cos(2x); U(0,t)=0; U(π,t)=0

In[28]:= pde51 = D[u[x, t], t] - 5 * D[u[x, t], x, x] ⩵ 0


NDSolvepde51, u[x, 0] ⩵ 1 - Cos[2 * x], u[0, t] ⩵ 0, u[Pi, t] ⩵ 0, u, x, 0, Pi, {t, 1, 10}
Plot3DEvaluate[u[x, t] /. %], x, 0, Pi, {t, 1, 10}
Out[28]=
u(0,1) [x, t] - 5 u(2,0) [x, t] ⩵ 0
Out[29]=

Domain: {{0., 3.14}, {1., 10.}}


u → InterpolatingFunction 
Output: scalar

Out[30]=
13

◼ Ques.2: Ut-5*Uxx=0; u(x,0)=x(1-π); U(0,t)=0; U(π,t)=0

In[31]:= pde51 = D[u[x, t], t] - 5 * D[u[x, t], x, x] ⩵ 0


NDSolvepde51, u[x, 0] ⩵ x * x - Pi, u[0, t] ⩵ 0, u[Pi, t] ⩵ 0, u, x, 0, Pi, {t, 1, 10}
Plot3DEvaluate[u[x, t] /. %], x, 0, Pi, {t, 1, 10}
Out[31]=
u(0,1) [x, t] - 5 u(2,0) [x, t] ⩵ 0
Out[32]=

Domain: {{0., 3.14}, {1., 10.}}


u → InterpolatingFunction 
Output: scalar

Out[33]=
14

◼ Ques.3: Ut-50*Uxx=0; u(x,0)=2Sin(2πx)+6Sin(8πx); U(0,t)=0; U(1,t)=0

In[34]:= pde52 = D[u[x, t], t] - 50 * D[u[x, t], x, x] ⩵ 0


NDSolvepde52, u[x, 0] ⩵ 2 * Sin[2 * Pi * x] + 6 * Sin[8 * Pi * x], u[0, t] ⩵ 0, u[1, t] ⩵ 0,
u, {x, 0, 1}, {t, 1, 10}
Plot3D[Evaluate[u[x, t] /. %], {x, 0, 1}, {t, 1, 10}]
Out[34]=
u(0,1) [x, t] - 50 u(2,0) [x, t] ⩵ 0
Out[35]=

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


u → InterpolatingFunction 
Output: scalar

Out[36]=
15

◼ Ques.4: 4Ut-Uxx=0; u(x,0)=2Sin(πx/2)-Sin(πx); U(0,t)=0; U(2,t)=0

In[37]:= pde53 = 4 * D[u[x, t], t] - D[u[x, t], x, x] ⩵ 0


NDSolvepde53, u[x, 0] ⩵ 2 * Sin[Pi * x / 2] - Sin[Pi * x], u[0, t] ⩵ 0, u[2, t] ⩵ 0,
u, {x, 0, 2}, {t, 1, 10}
Plot3D[Evaluate[u[x, t] /. %], {x, 0, 2}, {t, 1, 10}]
Out[37]=
4 u(0,1) [x, t] - u(2,0) [x, t] ⩵ 0
Out[38]=

Domain: {{0., 2.}, {1., 10.}}


u → InterpolatingFunction 
Output: scalar

Out[39]=
16

◼ Ques.5: Ut-9*Uxx=0; u(x,0)=x(1-π); U(0,t)=0; U(π,t)=0

In[40]:= pde54 = D[u[x, t], t] - 9 * D[u[x, t], x, x] ⩵ 0


NDSolvepde54, u[x, 0] ⩵ 2 * Sin[Pi * x / 2] - Sin[Pi * x], u[0, t] ⩵ 0, u[2, t] ⩵ 0,
u, {x, 0, 2}, {t, 1, 10}
Plot3D[Evaluate[u[x, t] /. %], {x, 0, 2}, {t, 1, 10}]
Out[40]=
u(0,1) [x, t] - 9 u(2,0) [x, t] ⩵ 0
Out[41]=

Domain: {{0., 2.}, {1., 10.}}


u → InterpolatingFunction 
Output: scalar

Out[42]=
17

Practical-06: Solution of one-dimensional


wave equation with initial conditions
★ U(x,0)=f(x), Ut(x,0)=g(x), x ∈ R, t>0

In[7]:= pde61 = Du[x, t], t, 2 - 4 * Dux, t, {x, 2} ⩵ 0
NDSolvepde61, u[x, 0] ⩵ x ^ 4, Derivative[0, 1][u][x, 0] ⩵ 0, u, {x, 0, 1}, {t, 0, 4}
Plot3DEvaluateux, t /. First[%], {x, 0, 10}, {t, 0, 4}, PlotRange → All

Out[7]= u(0,2) [x, t] - 4 u(2,0) [x, t] ⩵ 0

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


Out[8]= u → InterpolatingFunction 
Output: scalar

Out[9]=
18

★ U(x,0)=f(x), Ut(x,0)=g(x),U(0,t)=0 x ∈ R, t>0

In[19]:= pde62 = Du[x, t], t, 2 - 4 * Dux, t, {x, 2} ⩵ 0
NDSolvepde62, u[x, 0] ⩵ x ^ 4, Derivative[0, 1][u][x, 0] ⩵ Sin[x], u[0, t] ⩵ 0,
u, {x, 0, 1}, {t, 0, 4}
Plot3DEvaluateux, t /. First[%], {x, 0, 10}, {t, 0, 4}, PlotRange → All
Out[19]=

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


Out[20]=

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


u → InterpolatingFunction 
Output: scalar

Out[21]=

★ U(x,0)=f(x), Ut(x,0)=g(x),Ux(0,t)=0 x ∈ R, t>0


Out[18]=
u(0,2) [x, t] - 4 u(2,0) [x, t] ⩵ 0
19

In[31]:= pde7 = Du[x, t], t, 2 - 4 * Dux, t, {x, 2} ⩵ 0
NDSolvepde63, u[x, 0] ⩵ x ^ 2, Derivative[0, 1][u][x, 0] ⩵ 0, D[u[0, t], t] ⩵ 0,
u, {x, 0, 1}, {t, 0, 4}
Plot3DEvaluateux, t /. First[%], {x, 0, 10}, {t, 0, 4}, PlotRange → All
Out[31]=

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


Out[32]=

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


u → InterpolatingFunction 
Output: scalar

Out[33]=

Practical-07: Solution of traffic flow


problem with given initial conditions, and
plotting of the characteristic base curves
and the traffic density function
★ Ques.1: ρt+xSin(t)ρx = 0, with initial condition ρ0(x) = 1+ 1/(1+x^2 .

In[4]:= famsol1 = DSolvex '[t] ⩵ x[t] * Sin[t], x[0] ⩵ x0, x[t], t


x[t] → ⅇ x0
1-Cos[t]
Out[4]=
20

In[9]:= tab = Table[x[t] /. famsol1〚1〛 /. {x0 → k}, {k, 5, 20, 5}]


PlotEvaluate[tab], {t, - 10, 10}, PlotStyle → Thickness[0.01],
PlotLegends → Tabletabi, i, 1, 4, PlotLabel → "Characteristic base curves"

5 ⅇ , 10 ⅇ1-Cos[t] , 15 ⅇ1-Cos[t] , 20 ⅇ1-Cos[t] 


1-Cos[t]
Out[9]=

Out[10]=
Characteristic base curves
150

100
5 ⅇ1-cos(t)
10 ⅇ1-cos(t)
15 ⅇ1-cos(t)
50 20 ⅇ1-cos(t)

-10 -5 5 10

In[15]:= eqn71 = D[ρ[x, t], t] + x * Sin[t] * D[ρ[x, t], x] ⩵ 0;


sol71 = DSolve[{eqn71, ρ[x, 0] ⩵ 1 + 1 / (1 + x ^ 2)}, ρ[x, t], {x, t}]

DSolve: Inverse functions are being used by DSolve, so some solutions may not be found.
Out[16]=

2 ⅇ2 + ⅇ2 Cos[t] x2
ρ[x, t] → 
ⅇ2 + ⅇ2 Cos[t] x2

In[17]:= Plot3Dρ[x, t] /. sol71, {x, - 10, 10}, {t, - 10, 10}, PlotLabel → "Traffic density function"
Out[17]=
21

★ Ques.2: ρt+e^(t)*ρx = 2ρ, with initial condition ρ0(x) = 1+Sin^2(x)

In[42]:= famsol2 = DSolve[{x '[t] ⩵ Exp[t], x[0] ⩵ x0}, x[t], t]


tab1 = Table[x[t] /. famsol2〚1〛 /. {x0 → k}, {k, 4, 20, 4}]
PlotEvaluate[tab1], {t, - 4, 4}, PlotStyle → Thickness[0.01],
PlotLegends → Tabletab1i, i, 1, 5, PlotLabel → "Characteristic base curves"

Out[42]=
x[t] → - 1 + ⅇ + x0
t

Out[43]=
3 + ⅇ , 7 + ⅇt , 11 + ⅇt , 15 + ⅇt , 19 + ⅇt 
t

Out[44]=
Characteristic base curves

50

40 ⅇt + 3
ⅇt + 7
ⅇt + 11
30

20
ⅇt + 15
ⅇt + 19
10

-4 -2 2 4
22

In[48]:= eqn72 = D[ρ[x, t], t] + Exp[t] * D[ρ[x, t], x] ⩵ 2 * ρ[x, t];


sol72 = DSolveeqn72, ρ[x, 0] ⩵ 1 + Sin[x] ^ 2, ρ[x, t], {x, t}
Plot3Dρ[x, t] /. sol72, {x, - 4, 4}, {t, - 1, 1}, PlotLabel → "Traffic density function"
Out[49]=

ρ[x, t] → ⅇ 1 + Sin1 - ⅇt + x2 


2t

Out[50]=
23

★ Ques.3: ρt+2*ρx = 0, with initial condition ρ0(x) = e^(-x^2)

In[51]:= famsol3 = DSolve[{x '[t] ⩵ 2, x[0] ⩵ x0}, x[t], t]


tab2 = Table[x[t] /. famsol3〚1〛 /. {x0 → k}, {k, 1, 5, 1}]
PlotEvaluate[tab2], {t, - 2, 2}, PlotStyle → Thickness[0.01],
PlotLegends → Tabletab2i, i, 1, 5, PlotLabel → "Characteristic base curves"

Out[51]=
x[t] → 2 t + x0

Out[52]=
1 + 2 t, 2 + 2 t, 3 + 2 t, 4 + 2 t, 5 + 2 t

Out[53]=
Characteristic base curves

6 2t+1
2t+2
4
2t+3
2 2t+4
2t+5
-2 -1 1 2

-2
24

In[54]:= eqn73 = D[ρ[x, t], t] + 2 * D[ρ[x, t], x] ⩵ 0;


sol73 = DSolve[{eqn73, ρ[x, 0] ⩵ Exp[- x ^ 2]}, ρ[x, t], {x, t}]
Plot3Dρ[x, t] /. sol73, {x, - 4, 4}, {t, - 1, 1}, PlotLabel → "Traffic density function"
Out[55]=
x 2
-4 t- 
ρ[x, t] → ⅇ 2 

Out[56]=
25

★ Ques.4: ρt+2t^2*ρx = ρ^2, with initial condition ρ0(x) = Sin^2(x)

In[66]:= famsol4 = DSolve[{x '[t] ⩵ 2 * t ^ 2, x[0] ⩵ x0}, x[t], t]


tab3 = Table[x[t] /. famsol4〚1〛 /. {x0 → k}, {k, 3, 15, 3}]
PlotEvaluate[tab3], {t, - 3, 3}, PlotStyle → Thickness[0.01],
PlotLegends → Tabletab3i, i, 1, 5, PlotLabel → "Characteristic base curves"

Out[66]=
1
x[t] → 2 t3 + 3 x0
3
Out[67]=
1 1 1 1 1
 9 + 2 t3 , 18 + 2 t3 , 27 + 2 t3 , 36 + 2 t3 , 45 + 2 t3 
3 3 3 3 3
Out[68]=
Characteristic base curves

30

2 t 3 + 9
1
3
20
2 t 3 + 18
1
3

2 t 3 + 27
1
10
3

2 t 3 + 36
1
3

2 t 3 + 45
-3 -2 -1 1 2 3 1
3

-10
26

In[76]:= eqn74 = D[ρ[x, t], t] + 2 ** D[ρ[x, t], x] ⩵ 2 * ρ[x, t];


sol72 = DSolveeqn72, ρ[x, 0] ⩵ 1 + Sin[x] ^ 2, ρ[x, t], {x, t}
Plot3Dρ[x, t] /. sol72, {x, - 4, 4}, {t, - 1, 1}, PlotLabel → "Traffic density function"

DSolve: Inverse functions are being used by DSolve, so some solutions may not be found.
Out[77]=
2
ρ[x, t] → ⅇ 1 + Sin1 - ⅇt + x 
2t

Out[78]=

Das könnte Ihnen auch gefallen