Explicit Euler method for Fokker-Planck equation
$begingroup$
I'm trying to obtain an approximation of the solution of the following equation:
$$
leftlbrace begin{array}{l,l}
u_t = alpha u_{xx} + (beta u)_x, & u,alpha ,beta in [T_0,T_f]times [X_0,X_f]\
u(t=T_0,x) = u_0(x), & forall x in [X_0,X_f] \
u(t,x=X_0) = g_0(t), u(t,x=X_f) = g_f(t), & forall t in [T_0,Tf]
end{array}right.
$$
With $u_t = frac{partial u}{partial t}$, $(beta u)_x = frac{partial (beta u)}{partial x}$ and $u_{xx} = frac{partial^2 u}{(partial x)^2}$.
The thing is, there must be something wrong since whenever $beta$ is negative the approximations end up blowing up several times (so far it goes well for as long as this is avoided). I'll explain what I used for obtaining this approximations in case you can see if there's something I missed or simply is mistaken.
I used a finite difference method, by first applying the method of lines leaving the $t$ variable continuous as $x$ is discretized with $N+2$ nodes as follows:
$$
begin{array}{l}
Delta x = frac{X_f - X_0}{N+1} \
x_j = X_0 + jDelta x,hspace{.2cm} j in lbrace0,1,...,N+1rbrace \
u_j(t) simeq u(t,x_j)
end{array}
$$
Using central difference for $u_{xx}(x)$ ($u_{xx}simeq frac{u(x+Delta x) - 2u(x) + u(x-Delta x)}{(Delta x)^2}$) the equation results as follows:
$$
frac{partial u_j}{partial t}(t) = alpha(t,x_j)frac{u_{j+1} - 2u_j + u_{j-1}}{(Delta x)^2}(t) + beta(t,x_j)frac{u_{j+1}-u_{j-1}}{2Delta x}(t) + beta_x(t,x_j) u_j(t) = \
= u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Naming $a_1(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} + frac{beta(t,x_j)}{2Delta x}$, $a_2(t,x_j) = beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2}$ and $a_3(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x}$ the following system of equations is obtained:
$$
U_t(t) = A(t)U(t)
$$
With:
$$
begin{array}{l}
U_t(t) simeq (u_t(t,x_1),...,u_t(t,x_N))' \
U = (u_1(t),...,u_N(t))' \
g = (a_1(t,x_1)g_0(t),0,0,...,0,a_3(t,x_N)g_f(t))'
end{array}
$$
All of them being $Ntimes 1$. A is the following $Ntimes N$ matrix:
$$
left(begin{array}{c,c,c,c,c,c,c,c}
a_2(t,x1) & a_3(t,x_1) & 0 & 0 & ... & ...& ... & 0 \
a_1(t,x_2) & a_2(t,x_2) & a_3(t,x_2) & 0 & ... & ... & ... & 0 \
0 & a_1(t,x_3) & a_2(t,x_3) & a_3(t,x_3) & 0 & ... & ... & 0 \
0 & 0 & ddots & ddots & ddots & 0 & ... & 0 \
vdots & 0 & 0 & ddots & ddots & ddots & ... & vdots \
0 & ... & ... & 0 & 0 & a_1(t,x_{N-1}) & a_2(t,x_{N-1}) & a_3(t,x_{N-1}) \
0 & 0 & ... & ... & ... & 0 & a_1(t,x_N) & a_2(t,x_N)
end{array}right)
$$
Then I discretized time with $M+1$ nodes as follows:
$$
begin{array}{l}
Delta t = frac{T_f - T_0}{M}\
t_i = T_0 + iDelta t, hspace{.2cm} i in lbrace 0, 1, ..., Mrbrace \
u_j^i simeq u(t_i,x_j)
end{array}
$$
Applying forward Euler ($frac{partial u_j^i}{partial t} simeq frac{u_j^{i+1} - u_j^i}{Delta t}$) to the equation obtained after space discretization:
$$
frac{u_j^{i+1} - u_j^i}{Delta t} = u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Hence, we can state $u_j^{i+1}$ as:
$$
u_j^{i+1} = u_j^i + Delta t left(u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + \ u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)right)
$$
With the following notation:
$$
begin{array}{l}
U^i = (u_1^i,u_2^i,...,u_N^i)' \
h^i = (a_1(t_i,x_ 1)g_0(t_i)Delta t,0,...,0,a_3(t_i,x_N)g_f(t_i)Delta t )'
end{array}
$$
$U^i$ and $h^i$ with dimensions $N times 1$. Considering $I_N$ the $N times N$ identity matrix we have:
$$
U^{i+1} = left(I_N + Delta t A(t_i)right)U^i + h^i, hspace{.2cm} 1 leq i leq N
$$
I plotted the approximations at some time values and, as I said before, whenever $beta$ has negative values several blow ups appear. I would like to know if there's something wrong with the method I used or mistakes during the process so I can determine whether the error lies in the method or the code.
Thank you in advance!
P.S: The discretizations are taken in a way the Courant-Friedrichs-Levy condition is satisfied, that is not the issue.
ordinary-differential-equations pde numerical-methods finite-differences
$endgroup$
add a comment |
$begingroup$
I'm trying to obtain an approximation of the solution of the following equation:
$$
leftlbrace begin{array}{l,l}
u_t = alpha u_{xx} + (beta u)_x, & u,alpha ,beta in [T_0,T_f]times [X_0,X_f]\
u(t=T_0,x) = u_0(x), & forall x in [X_0,X_f] \
u(t,x=X_0) = g_0(t), u(t,x=X_f) = g_f(t), & forall t in [T_0,Tf]
end{array}right.
$$
With $u_t = frac{partial u}{partial t}$, $(beta u)_x = frac{partial (beta u)}{partial x}$ and $u_{xx} = frac{partial^2 u}{(partial x)^2}$.
The thing is, there must be something wrong since whenever $beta$ is negative the approximations end up blowing up several times (so far it goes well for as long as this is avoided). I'll explain what I used for obtaining this approximations in case you can see if there's something I missed or simply is mistaken.
I used a finite difference method, by first applying the method of lines leaving the $t$ variable continuous as $x$ is discretized with $N+2$ nodes as follows:
$$
begin{array}{l}
Delta x = frac{X_f - X_0}{N+1} \
x_j = X_0 + jDelta x,hspace{.2cm} j in lbrace0,1,...,N+1rbrace \
u_j(t) simeq u(t,x_j)
end{array}
$$
Using central difference for $u_{xx}(x)$ ($u_{xx}simeq frac{u(x+Delta x) - 2u(x) + u(x-Delta x)}{(Delta x)^2}$) the equation results as follows:
$$
frac{partial u_j}{partial t}(t) = alpha(t,x_j)frac{u_{j+1} - 2u_j + u_{j-1}}{(Delta x)^2}(t) + beta(t,x_j)frac{u_{j+1}-u_{j-1}}{2Delta x}(t) + beta_x(t,x_j) u_j(t) = \
= u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Naming $a_1(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} + frac{beta(t,x_j)}{2Delta x}$, $a_2(t,x_j) = beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2}$ and $a_3(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x}$ the following system of equations is obtained:
$$
U_t(t) = A(t)U(t)
$$
With:
$$
begin{array}{l}
U_t(t) simeq (u_t(t,x_1),...,u_t(t,x_N))' \
U = (u_1(t),...,u_N(t))' \
g = (a_1(t,x_1)g_0(t),0,0,...,0,a_3(t,x_N)g_f(t))'
end{array}
$$
All of them being $Ntimes 1$. A is the following $Ntimes N$ matrix:
$$
left(begin{array}{c,c,c,c,c,c,c,c}
a_2(t,x1) & a_3(t,x_1) & 0 & 0 & ... & ...& ... & 0 \
a_1(t,x_2) & a_2(t,x_2) & a_3(t,x_2) & 0 & ... & ... & ... & 0 \
0 & a_1(t,x_3) & a_2(t,x_3) & a_3(t,x_3) & 0 & ... & ... & 0 \
0 & 0 & ddots & ddots & ddots & 0 & ... & 0 \
vdots & 0 & 0 & ddots & ddots & ddots & ... & vdots \
0 & ... & ... & 0 & 0 & a_1(t,x_{N-1}) & a_2(t,x_{N-1}) & a_3(t,x_{N-1}) \
0 & 0 & ... & ... & ... & 0 & a_1(t,x_N) & a_2(t,x_N)
end{array}right)
$$
Then I discretized time with $M+1$ nodes as follows:
$$
begin{array}{l}
Delta t = frac{T_f - T_0}{M}\
t_i = T_0 + iDelta t, hspace{.2cm} i in lbrace 0, 1, ..., Mrbrace \
u_j^i simeq u(t_i,x_j)
end{array}
$$
Applying forward Euler ($frac{partial u_j^i}{partial t} simeq frac{u_j^{i+1} - u_j^i}{Delta t}$) to the equation obtained after space discretization:
$$
frac{u_j^{i+1} - u_j^i}{Delta t} = u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Hence, we can state $u_j^{i+1}$ as:
$$
u_j^{i+1} = u_j^i + Delta t left(u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + \ u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)right)
$$
With the following notation:
$$
begin{array}{l}
U^i = (u_1^i,u_2^i,...,u_N^i)' \
h^i = (a_1(t_i,x_ 1)g_0(t_i)Delta t,0,...,0,a_3(t_i,x_N)g_f(t_i)Delta t )'
end{array}
$$
$U^i$ and $h^i$ with dimensions $N times 1$. Considering $I_N$ the $N times N$ identity matrix we have:
$$
U^{i+1} = left(I_N + Delta t A(t_i)right)U^i + h^i, hspace{.2cm} 1 leq i leq N
$$
I plotted the approximations at some time values and, as I said before, whenever $beta$ has negative values several blow ups appear. I would like to know if there's something wrong with the method I used or mistakes during the process so I can determine whether the error lies in the method or the code.
Thank you in advance!
P.S: The discretizations are taken in a way the Courant-Friedrichs-Levy condition is satisfied, that is not the issue.
ordinary-differential-equations pde numerical-methods finite-differences
$endgroup$
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15
add a comment |
$begingroup$
I'm trying to obtain an approximation of the solution of the following equation:
$$
leftlbrace begin{array}{l,l}
u_t = alpha u_{xx} + (beta u)_x, & u,alpha ,beta in [T_0,T_f]times [X_0,X_f]\
u(t=T_0,x) = u_0(x), & forall x in [X_0,X_f] \
u(t,x=X_0) = g_0(t), u(t,x=X_f) = g_f(t), & forall t in [T_0,Tf]
end{array}right.
$$
With $u_t = frac{partial u}{partial t}$, $(beta u)_x = frac{partial (beta u)}{partial x}$ and $u_{xx} = frac{partial^2 u}{(partial x)^2}$.
The thing is, there must be something wrong since whenever $beta$ is negative the approximations end up blowing up several times (so far it goes well for as long as this is avoided). I'll explain what I used for obtaining this approximations in case you can see if there's something I missed or simply is mistaken.
I used a finite difference method, by first applying the method of lines leaving the $t$ variable continuous as $x$ is discretized with $N+2$ nodes as follows:
$$
begin{array}{l}
Delta x = frac{X_f - X_0}{N+1} \
x_j = X_0 + jDelta x,hspace{.2cm} j in lbrace0,1,...,N+1rbrace \
u_j(t) simeq u(t,x_j)
end{array}
$$
Using central difference for $u_{xx}(x)$ ($u_{xx}simeq frac{u(x+Delta x) - 2u(x) + u(x-Delta x)}{(Delta x)^2}$) the equation results as follows:
$$
frac{partial u_j}{partial t}(t) = alpha(t,x_j)frac{u_{j+1} - 2u_j + u_{j-1}}{(Delta x)^2}(t) + beta(t,x_j)frac{u_{j+1}-u_{j-1}}{2Delta x}(t) + beta_x(t,x_j) u_j(t) = \
= u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Naming $a_1(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} + frac{beta(t,x_j)}{2Delta x}$, $a_2(t,x_j) = beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2}$ and $a_3(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x}$ the following system of equations is obtained:
$$
U_t(t) = A(t)U(t)
$$
With:
$$
begin{array}{l}
U_t(t) simeq (u_t(t,x_1),...,u_t(t,x_N))' \
U = (u_1(t),...,u_N(t))' \
g = (a_1(t,x_1)g_0(t),0,0,...,0,a_3(t,x_N)g_f(t))'
end{array}
$$
All of them being $Ntimes 1$. A is the following $Ntimes N$ matrix:
$$
left(begin{array}{c,c,c,c,c,c,c,c}
a_2(t,x1) & a_3(t,x_1) & 0 & 0 & ... & ...& ... & 0 \
a_1(t,x_2) & a_2(t,x_2) & a_3(t,x_2) & 0 & ... & ... & ... & 0 \
0 & a_1(t,x_3) & a_2(t,x_3) & a_3(t,x_3) & 0 & ... & ... & 0 \
0 & 0 & ddots & ddots & ddots & 0 & ... & 0 \
vdots & 0 & 0 & ddots & ddots & ddots & ... & vdots \
0 & ... & ... & 0 & 0 & a_1(t,x_{N-1}) & a_2(t,x_{N-1}) & a_3(t,x_{N-1}) \
0 & 0 & ... & ... & ... & 0 & a_1(t,x_N) & a_2(t,x_N)
end{array}right)
$$
Then I discretized time with $M+1$ nodes as follows:
$$
begin{array}{l}
Delta t = frac{T_f - T_0}{M}\
t_i = T_0 + iDelta t, hspace{.2cm} i in lbrace 0, 1, ..., Mrbrace \
u_j^i simeq u(t_i,x_j)
end{array}
$$
Applying forward Euler ($frac{partial u_j^i}{partial t} simeq frac{u_j^{i+1} - u_j^i}{Delta t}$) to the equation obtained after space discretization:
$$
frac{u_j^{i+1} - u_j^i}{Delta t} = u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Hence, we can state $u_j^{i+1}$ as:
$$
u_j^{i+1} = u_j^i + Delta t left(u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + \ u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)right)
$$
With the following notation:
$$
begin{array}{l}
U^i = (u_1^i,u_2^i,...,u_N^i)' \
h^i = (a_1(t_i,x_ 1)g_0(t_i)Delta t,0,...,0,a_3(t_i,x_N)g_f(t_i)Delta t )'
end{array}
$$
$U^i$ and $h^i$ with dimensions $N times 1$. Considering $I_N$ the $N times N$ identity matrix we have:
$$
U^{i+1} = left(I_N + Delta t A(t_i)right)U^i + h^i, hspace{.2cm} 1 leq i leq N
$$
I plotted the approximations at some time values and, as I said before, whenever $beta$ has negative values several blow ups appear. I would like to know if there's something wrong with the method I used or mistakes during the process so I can determine whether the error lies in the method or the code.
Thank you in advance!
P.S: The discretizations are taken in a way the Courant-Friedrichs-Levy condition is satisfied, that is not the issue.
ordinary-differential-equations pde numerical-methods finite-differences
$endgroup$
I'm trying to obtain an approximation of the solution of the following equation:
$$
leftlbrace begin{array}{l,l}
u_t = alpha u_{xx} + (beta u)_x, & u,alpha ,beta in [T_0,T_f]times [X_0,X_f]\
u(t=T_0,x) = u_0(x), & forall x in [X_0,X_f] \
u(t,x=X_0) = g_0(t), u(t,x=X_f) = g_f(t), & forall t in [T_0,Tf]
end{array}right.
$$
With $u_t = frac{partial u}{partial t}$, $(beta u)_x = frac{partial (beta u)}{partial x}$ and $u_{xx} = frac{partial^2 u}{(partial x)^2}$.
The thing is, there must be something wrong since whenever $beta$ is negative the approximations end up blowing up several times (so far it goes well for as long as this is avoided). I'll explain what I used for obtaining this approximations in case you can see if there's something I missed or simply is mistaken.
I used a finite difference method, by first applying the method of lines leaving the $t$ variable continuous as $x$ is discretized with $N+2$ nodes as follows:
$$
begin{array}{l}
Delta x = frac{X_f - X_0}{N+1} \
x_j = X_0 + jDelta x,hspace{.2cm} j in lbrace0,1,...,N+1rbrace \
u_j(t) simeq u(t,x_j)
end{array}
$$
Using central difference for $u_{xx}(x)$ ($u_{xx}simeq frac{u(x+Delta x) - 2u(x) + u(x-Delta x)}{(Delta x)^2}$) the equation results as follows:
$$
frac{partial u_j}{partial t}(t) = alpha(t,x_j)frac{u_{j+1} - 2u_j + u_{j-1}}{(Delta x)^2}(t) + beta(t,x_j)frac{u_{j+1}-u_{j-1}}{2Delta x}(t) + beta_x(t,x_j) u_j(t) = \
= u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Naming $a_1(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} + frac{beta(t,x_j)}{2Delta x}$, $a_2(t,x_j) = beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2}$ and $a_3(t,x_j) = frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x}$ the following system of equations is obtained:
$$
U_t(t) = A(t)U(t)
$$
With:
$$
begin{array}{l}
U_t(t) simeq (u_t(t,x_1),...,u_t(t,x_N))' \
U = (u_1(t),...,u_N(t))' \
g = (a_1(t,x_1)g_0(t),0,0,...,0,a_3(t,x_N)g_f(t))'
end{array}
$$
All of them being $Ntimes 1$. A is the following $Ntimes N$ matrix:
$$
left(begin{array}{c,c,c,c,c,c,c,c}
a_2(t,x1) & a_3(t,x_1) & 0 & 0 & ... & ...& ... & 0 \
a_1(t,x_2) & a_2(t,x_2) & a_3(t,x_2) & 0 & ... & ... & ... & 0 \
0 & a_1(t,x_3) & a_2(t,x_3) & a_3(t,x_3) & 0 & ... & ... & 0 \
0 & 0 & ddots & ddots & ddots & 0 & ... & 0 \
vdots & 0 & 0 & ddots & ddots & ddots & ... & vdots \
0 & ... & ... & 0 & 0 & a_1(t,x_{N-1}) & a_2(t,x_{N-1}) & a_3(t,x_{N-1}) \
0 & 0 & ... & ... & ... & 0 & a_1(t,x_N) & a_2(t,x_N)
end{array}right)
$$
Then I discretized time with $M+1$ nodes as follows:
$$
begin{array}{l}
Delta t = frac{T_f - T_0}{M}\
t_i = T_0 + iDelta t, hspace{.2cm} i in lbrace 0, 1, ..., Mrbrace \
u_j^i simeq u(t_i,x_j)
end{array}
$$
Applying forward Euler ($frac{partial u_j^i}{partial t} simeq frac{u_j^{i+1} - u_j^i}{Delta t}$) to the equation obtained after space discretization:
$$
frac{u_j^{i+1} - u_j^i}{Delta t} = u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)
$$
Hence, we can state $u_j^{i+1}$ as:
$$
u_j^{i+1} = u_j^i + Delta t left(u_{j-1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} - frac{beta(t,x_j)}{2Delta x} right) + \ u_j(t)left( beta_x(t,xj) - 2frac{alpha(t,x_j)}{(Delta x)^2} right) + u_{j+1}(t)left( frac{alpha(t,x_j)}{(Delta x)^2} +frac{beta(t,x_j)}{2Delta x} right)right)
$$
With the following notation:
$$
begin{array}{l}
U^i = (u_1^i,u_2^i,...,u_N^i)' \
h^i = (a_1(t_i,x_ 1)g_0(t_i)Delta t,0,...,0,a_3(t_i,x_N)g_f(t_i)Delta t )'
end{array}
$$
$U^i$ and $h^i$ with dimensions $N times 1$. Considering $I_N$ the $N times N$ identity matrix we have:
$$
U^{i+1} = left(I_N + Delta t A(t_i)right)U^i + h^i, hspace{.2cm} 1 leq i leq N
$$
I plotted the approximations at some time values and, as I said before, whenever $beta$ has negative values several blow ups appear. I would like to know if there's something wrong with the method I used or mistakes during the process so I can determine whether the error lies in the method or the code.
Thank you in advance!
P.S: The discretizations are taken in a way the Courant-Friedrichs-Levy condition is satisfied, that is not the issue.
ordinary-differential-equations pde numerical-methods finite-differences
ordinary-differential-equations pde numerical-methods finite-differences
edited Jan 10 at 21:01
Stonelord
asked Jan 10 at 18:55
StonelordStonelord
164
164
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15
add a comment |
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069050%2fexplicit-euler-method-for-fokker-planck-equation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3069050%2fexplicit-euler-method-for-fokker-planck-equation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You have a consistent sign error in the first beta term (for $u_{j-1}$) in the discretization formulas. Did you consider approximating $(βu)_x$ as $$frac{β(t,x_{j+1})u_{j+1}(t)-β(t,x_{j-1})u_{j-1}(t)}{2Δx}?$$
$endgroup$
– LutzL
Jan 10 at 19:37
$begingroup$
The $u_{j-1}$ was a typo error, It's been already fixed. Sorry for the ambiguity, I'll try your approach for the $(beta u)_x$ derivative. Yet the one I've used is also applicable right?
$endgroup$
– Stonelord
Jan 10 at 21:06
$begingroup$
Yes, if you have the derivative of $β$ in some algorithmic form, you can use both. And both have the same error order and should give similar results.
$endgroup$
– LutzL
Jan 10 at 21:15