Mathematica Wave Equation Plot with Mathematica: Solutions for Different Regions and Time

AI Thread Summary
The discussion focuses on plotting the wave equation solution in Mathematica, specifically the piecewise function defined for different regions of (x, t). Users are encountering issues with the initial code, which employs Piecewise to define the function u[x, t]. An alternative approach using If statements is suggested for clarity and functionality. The regions R1 through R6 are outlined to determine the behavior of the function based on the values of x and t. The conversation emphasizes the need for correct syntax and logical structuring in Mathematica to successfully visualize the wave equation.
Dustinsfl
Messages
2,217
Reaction score
5
$$
u(x,t) = \frac{1}{2}\int_{x - t}^{x + t}g(s)ds = \begin{cases}
t, & (x,t)\in R_1\\
\frac{1}{2}(1 - x + t), & (x,t)\in R_2\\
\frac{1}{2}(x + t + 1), & (x,t)\in R_3\\
1, & (x,t)\in R_4\\
0, & (x,t)\in R_5,R_6
\end{cases}
$$
where
\begin{alignat*}{3}
R_1 & = & \{(x,t):-1 < x - t < 1\text{ and } -1 < x + t < 1\}\\
R_2 & = & \{(x,t):-1 < x - t < 1\text{ and } x + t > 1\}\\
R_3 & = & \{(x,t):x - t < -1\text{ and } -1 < x + t < 1\}\\
R_4 & = & \{(x,t):x - t < -1\text{ and } x + t > 1\}\\
R_5 & = & \{(x,t):x + t < -1\}\\
R_5 & = & \{(x,t):x - t > 1\}
\end{alignat*}

How do I plot this in the Mathematica?
I tried this but it doesn't work.
Code:
u[x_, t_] = 
  Piecewise[{{t, -1 < x - t < 1 And - 1 < x + t < 
      1}, {1/2 (1 - x + t), -1 < x - t < 1 And x + t > 
      1}, {1/2 (x + t + 1), x - t < -1 And - 1 < x + t < 1}, {1, 
     x - t < -1 And x + t > 1}, {0, x + t < -1}, {0, x - t > 1}}];
Manipulate[Plot[u[x, t], {x, -10, 10}], {t, 0, 1, .01}]
 
Last edited:
Physics news on Phys.org
I would probably use If statements to define the function. Something like this:

Code:
u[x_,t_]=If[-1<x-t && x-t<1 && -1<x+t && x+t<1,t,
If[-1<x-t && x-t<1 && x+t>1,(1/2)(1-x+t),
...
...]]
 

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
2
Views
2K
Replies
5
Views
2K
Back
Top