How to solve simple 2D space-time PDE numerically

In summary: 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.
  • #1
tworitdash
107
26
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 Delta2
Physics news on Phys.org
  • #2
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 tworitdash
  • #3
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 [itex] \eta(x) [/itex] don't change at the edges). Here, I use the terms in the brackets as indices. So, for example [itex] \eta(x + 1, t) = \eta(x + \Delta x, t) [/itex]

$$ \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
 
  • #4
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.
 
  • #5
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 [itex]\int 1/u\,du = \log u + C[/itex] rather than [itex]\int 1/u\,du = \log|u| + C[/itex]. However I don't think your result is correct.

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

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

Related to How to solve simple 2D space-time PDE numerically

1. What is a 2D space-time PDE?

A 2D space-time PDE (partial differential equation) is a mathematical equation that describes the evolution of a physical system in both space and time. It involves multiple independent variables, typically representing spatial coordinates and time, and their respective derivatives.

2. Why is it important to solve 2D space-time PDEs numerically?

Solving 2D space-time PDEs numerically allows us to obtain approximate solutions to complex physical systems that cannot be solved analytically. This is useful in many fields of science and engineering, such as fluid dynamics, electromagnetism, and quantum mechanics.

3. What are the steps involved in solving a 2D space-time PDE numerically?

The steps involved in solving a 2D space-time PDE numerically include discretization of the equations, selection of a numerical method, implementation of the method using a computer program, and analysis of the results for accuracy and stability.

4. What are some commonly used numerical methods for solving 2D space-time PDEs?

Some commonly used numerical methods for solving 2D space-time PDEs include finite difference methods, finite element methods, and spectral methods. Each method has its own advantages and limitations, and the choice of method depends on the specific problem being solved.

5. What are some challenges in solving 2D space-time PDEs numerically?

Some challenges in solving 2D space-time PDEs numerically include dealing with complex boundary conditions, ensuring stability and accuracy of the numerical method, and handling high-dimensional systems. Additionally, the computational resources required for solving large-scale problems can also be a challenge.

Similar threads

  • Differential Equations
Replies
3
Views
749
Replies
5
Views
2K
Replies
4
Views
2K
  • Differential Equations
Replies
3
Views
1K
  • Differential Equations
Replies
7
Views
2K
  • Differential Equations
Replies
5
Views
319
  • Differential Equations
Replies
3
Views
2K
  • Differential Equations
Replies
2
Views
584
Replies
13
Views
2K
Replies
2
Views
1K
Back
Top