​
Given the following problem
u
t
-
v
2
·
u
xx
+
v
2
·
2
x
·u(x)0
u(x,0)f(x)
​​Where
f(x)
y
1
(x)+0.2
y
4
(x)+0.01
y
6
(x)
​​
y
n
are the Eigenfunctions that defined as
y
n
(x)exp
-
2
x
2
H
n
(x)
​​By separation we assume
u(x,t)X(x)T(x
)​I have found that the general solution of
T
is​
T(x)
c
1
-λvt
e
​and the general solution of $X$ is ​
X
n
(x)exp
-
2
x
2
H
n
(x)
​​So the general solution to our initial problem is ​
u
n
(x,t)
∞
∑
n1
A
n
exp
-
2
x
2
H
n
(x)
c
1
-λvt
e
​​Using the I.C we got
u(x,0)
∞
∑
n1
A
n
exp
-
2
x
2
H
n
(x)f(x)

Analytical solution

In[]:=
Clear["Global`*"]
​
In[]:=
f[x_]:=Exp[-x^2/2](1+0.2*HermiteH[4,x]+0.01*HermiteH[6,x])​​n=10;​​
In[]:=
A=Table[1/(Sqrt[Pi]2^mm!)Integrate[f[x]HermiteH[m,x]Exp[x^2/2],{x,0,1}],{m,1,n}];​​u[x_,t_]:=Sum[A[[m]]Exp[-m/2t]Exp[-x^2/2]HermiteH[m-1,x],{m,1,n}]​​
In[]:=
Plot[{u[x,0],u[x,0.3],u[x,0.7]},{x,-20,20},PlotRange->All,PlotLegends->{"t=0","t=0.3","t=0.7"}]​​
Out[]=
-20
-10
10
20
-0.2
0.2
0.4
t=0
t=0.3
t=0.7
In[]:=
fig1=Plot3D[u[x,t],{t,0,10},{x,-21,21},PlotRangeAll,ColorFunction"BlueGreenYellow"]
Out[]=

Numerical Solution

In[]:=
Clear["Global`*"]
(*DefinetheEigenfunctions*)
In[]:=
eigen[n_]:=n+1/2
In[]:=
Her[n_]:=HermiteH[n,x]
In[]:=
Y[n_]:=Exp[-x^2/2]*Her[n]
In[]:=
Y[1]
Out[]=
2
-
2
x
2

x
In[]:=
Y[4]
Out[]=
-
2
x
2

(12-48
2
x
+16
4
x
)
In[]:=
Y[6]
Out[]=
-
2
x
2

(-120+720
2
x
-480
4
x
+64
6
x
)
(*ThefunctionoftheInitialCondition*)
In[]:=
f[x_]=Y[1]+0.2Y[4]+0.01Y[6]
Out[]=
2
-
2
x
2

x+0.2
-
2
x
2

(12-48
2
x
+16
4
x
)+0.01
-
2
x
2

(-120+720
2
x
-480
4
x
+64
6
x
)
(*InitialCondition*)
In[]:=
IC=u[x,0]f[x]
Out[]=
u[x,0]2
-
2
x
2

x+0.2
-
2
x
2

(12-48
2
x
+16
4
x
)+0.01
-
2
x
2

(-120+720
2
x
-480
4
x
+64
6
x
)
(*DefinePDE*)
In[]:=
PDE=
∂
t
u[x,t]-
1
2
*
∂
x,x
u[x,t]+
1
2
*
2
x
*u[x,t]0
Out[]=
1
2
2
x
u[x,t]+
(0,1)
u
[x,t]-
1
2
(2,0)
u
[x,t]0
(*BountaryConditions*)
In[]:=
BCs={u[-21,t]==0,u[21,t]==0}
Out[]=
{u[-21,t]0,u[21,t]0}
In[]:=
sol=First[NDSolve[{PDE,BCs,IC},u,{t,0,10},{x,-21,21}]]
Out[]=
uInterpolatingFunction
Domain: {{-21.,21.},{0.,10.}}
Output: scalar

In[]:=
Plot3D[u[x,t]/.sol,{t,0,10},{x,-21,21},PlotRangeAll,ColorFunction"RustTones"]
Out[]=
In[]:=
Manipulate[Plot[u[x,t]/.sol/.t->t0,{x,-21,21},PlotRange->{Automatic,{-4,4}},GridLines->Automatic,GridLinesStyle->LightGray,PlotStyle->Red],{{t0,0,"time"},0,1,.01,Appearance->"Labeled"}]
Out[]=
​
time
0