How to solve simple 2D space-time PDE numerically

Click For Summary
SUMMARY

This discussion focuses on numerically solving a 2D space-time partial differential equation (PDE) represented by $$ \frac{\partial \eta(x, t)}{\partial t} + \sin\Big(\frac{2 \pi x}{L}\Big) \frac{\partial \eta(x, t)}{\partial x} = 0 $$ using MATLAB and Mathematica. The initial condition is $$ \eta(x, 0) = \sin\Big(\frac{2 \pi x}{L}\Big) $$, and boundary conditions are $$ \eta(0, t) = 0 $$ and $$ \eta(L, t) = 0 $$. The numerical solution diverges from the Mathematica solution due to errors in discretization, which can be mitigated by reducing the time step $$ \Delta t $$ and spatial grid spacing $$ \Delta x $$. The method of characteristics is also discussed as an alternative approach to improve accuracy.

PREREQUISITES
  • Understanding of partial differential equations (PDEs)
  • Familiarity with numerical methods for PDEs
  • Proficiency in MATLAB for numerical simulations
  • Basic knowledge of Mathematica for symbolic computation
NEXT STEPS
  • Implement adaptive time-stepping techniques in MATLAB for improved accuracy
  • Explore the method of characteristics for solving hyperbolic PDEs
  • Learn about stability analysis in numerical methods for PDEs
  • Investigate the impact of boundary conditions on numerical solutions
USEFUL FOR

Mathematicians, physicists, and engineers involved in computational modeling of PDEs, particularly those interested in numerical analysis and simulation techniques.

tworitdash
Messages
104
Reaction score
25
I have a 2D space-time PDE and I want to solve it numerically over the time axis. The time initial field is already known with respect to space, i.e., the spatial distribution is already known at time `t = 0`. I solved the same PDF in Mathematica and got a solution. I tried to solve it numerically step wise in time and implemented the same numerical update equation in MATLAB. Both give me different results. I checked the paper where I took the question from and with only a visual inspection it feels like the one from Mathematica is more accurate. As time progresses, the numerical model becomes more erroneous.

The PDE:$$ \frac{\partial \eta(x, t)}{\partial t} + \sin\Big(\frac{2 \pi x}{L}\Big) \frac{\partial \eta(x, t)}{\partial x} = 0 $$

Boundary conditions: At the spatial boundaries, the function has a value of `0`.$$ \eta(0, t) = 0, \eta(L, t) = 0 $$The time initial field is given by

$$ \eta(x, 0) = \sin\Big(\frac{2 \pi x}{L}\Big) $$The solution from mathematica is:$$ \eta(x, t) = \sin\Big( 2 \cot^{-1} \Big[ e^{\frac{2 \pi t + L \log\Bigg[\cos\Big({\frac{\pi x}{L}\Big)}\Bigg] - L \log\Bigg[ \sin\Big({\frac{\pi x}{L}\Big)} \Bigg]}{L}} \Big] \Big) $$I solve the numerical version by integrating the PDE with respect to t, then, I get the follwing

$$ \eta(x, t + 1) = \eta(x, t) - \sin(2 \frac{\pi x}{L}) \frac{\Delta t }{\Delta x} [\eta(x+1, t) - \eta(x, t)] $$

The results are given in the picture for x from 0 to 20 with a step of 1 and t from 0 to 1.3 with a step of 0.1.

However, they both satisfy the boundary conditions. The peak values are different.
Eta.PNG
 
Last edited:
  • Like
Likes   Reactions: Delta2
Physics news on Phys.org
The numerical solution will always have errors, since you are approximating a continuous function as a set of discrete data points. Try decreasing the size of the time step Δt, and possibly also the space grid spacing Δx. As you decrease those, the numerical solution should approach the Mathematica solution. Does it?
 
  • Like
Likes   Reactions: tworitdash
phyzguy said:
The numerical solution will always have errors, since you are approximating a continuous function as a set of discrete data points. Try decreasing the size of the time step Δt, and possibly also the space grid spacing Δx. As you decrease those, the numerical solution should approach the Mathematica solution. Does it?
Yes, indeed it does. As the paper had more accurate values at the peak with numerical solution (although they didn't show the solution), I was wondering. One interesting thing I tried yesterday. I changed the definition of the derivative with respect to space on the right hand side and applied Neuman's boundary condition at the edges (values of \eta(x) don't change at the edges). Here, I use the terms in the brackets as indices. So, for example \eta(x + 1, t) = \eta(x + \Delta x, t)

$$ \frac{\partial\eta(x, t)}{\partial x} = \frac{\eta(x + 1) - \eta(x - 1)}{2 \Delta x} $$

Now the results have been improved.

Eta2.PNG
 
On examining your solution from mathematica I found a problem. For the initial condition,
$$
\eta (L,t) = 0
$$
the exponential argument of ##\cot^{-1}## is
$$
e^{\frac{\pi t}{L} + \log(-1)-\log(0)}=e^{\frac{\pi t}{L} + i\pi + \infty}
$$
That is, the argument is complex at the boundary condition. This bothers me, so I solved the problem using the method of characteristics. I get,
$$
\eta (x,t)=\sin(2\cot^{-1}(\frac{e^{ \left [ (\frac{-2\pi t}{L})+\log(2\sin(\sin(\frac{2\pi}{L}x))-\log (2\cos(\sin(\frac{2\pi}{L}x))))\right ]}}{2}))
$$
I don't have mathematica, but I suspect your numerical solution might be accurate but you may have made an error in however you input the problem to the mathematica software.
 
Fred Wright said:
On examining your solution from mathematica I found a problem. For the initial condition,
$$
\eta (L,t) = 0
$$
the exponential argument of ##\cot^{-1}## is
$$
e^{\frac{\pi t}{L} + \log(-1)-\log(0)}=e^{\frac{\pi t}{L} + i\pi + \infty}
$$

That is, the argument is complex at the boundary condition.

This bothers me, so I solved the problem using the method of characteristics. I get,
$$
\eta (x,t)=\sin(2\cot^{-1}(\frac{e^{ \left [ (\frac{-2\pi t}{L})+\log(2\sin(\sin(\frac{2\pi}{L}x))-\log (2\cos(\sin(\frac{2\pi}{L}x))))\right ]}}{2}))
$$
I don't have mathematica, but I suspect your numerical solution might be accurate but you may have made an error in however you input the problem to the mathematica software.

The Mathematica result is basically correct; it's just made the schoolboy error of using \int 1/u\,du = \log u + C rather than \int 1/u\,du = \log|u| + C. However I don't think your result is correct.

The method of characteristics gives that \eta is constant on curves (x(t),t) where, for x(0) \neq 0, L/2, L,
<br /> \int_{x(0)}^{x(t)} \csc(2\pi x/L)\,dx = t or <br /> \left[\ln|\csc(2\pi x/L) + \cot(2\pi x/L)|\right]_{x(0)}^{x(t)} <br /> = \left[\log |\cot(\pi x/L)|\right]_{x(0)}^{x(t)}= -2\pi t/L. Solving this yields <br /> \cot(\pi x(t)/L) = \cot(\pi x(0)/L) e^{-2\pi t/L}, irrespective of the sign of\cot(\pi x/L). Applying the initial condition then gives <br /> \eta(x,t) = \sin\left(<br /> 2 \operatorname{arccot}\left(<br /> \cot(\pi x/L) e^{2\pi t/L}<br /> \right)<br /> \right). This holds also for x(0) = 0, L/2, L where the characteristic is (x,t) = (x(0),t) and the initial condition is \eta(x_0,0) = 0 provided one identifies \operatorname{arccot}(\infty) = 0. Simplifying the Mathematica expression will, for positive arguments of \log, reduce to the above.
 
  • Like
Likes   Reactions: tworitdash
pasmith said:
The Mathematica result is basically correct; it's just made the schoolboy error of using \int 1/u\,du = \log u + C rather than \int 1/u\,du = \log|u| + C. However I don't think your result is correct.

The method of characteristics gives that \eta is constant on curves (x(t),t) where, for x(0) \neq 0, L/2, L,
<br /> \int_{x(0)}^{x(t)} \csc(2\pi x/L)\,dx = t or <br /> \left[\ln|\csc(2\pi x/L) + \cot(2\pi x/L)|\right]_{x(0)}^{x(t)} <br /> = \left[\log |\cot(\pi x/L)|\right]_{x(0)}^{x(t)}= -2\pi t/L. Solving this yields <br /> \cot(\pi x(t)/L) = \cot(\pi x(0)/L) e^{-2\pi t/L}, irrespective of the sign of\cot(\pi x/L). Applying the initial condition then gives <br /> \eta(x,t) = \sin\left(<br /> 2 \operatorname{arccot}\left(<br /> \cot(\pi x/L) e^{2\pi t/L}<br /> \right)<br /> \right). This holds also for x(0) = 0, L/2, L where the characteristic is (x,t) = (x(0),t) and the initial condition is \eta(x_0,0) = 0 provided one identifies \operatorname{arccot}(\infty) = 0. Simplifying the Mathematica expression will, for positive arguments of \log, reduce to the above.
Nice Observation!
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 36 ·
2
Replies
36
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K