| > | # two
examples plot solution of wave equation # the initial data: u(x,0)=f(x), u_t(x,0)=g(x) # |
| > | # example 1: f(x)=sin(2*x); g(x)=x*cos(x); |
| > | L:=Pi;
C:=1; T:=2*Pi; N:=20; f:=x->sin(2*x); # f:=x->piecewise(x<1/3,3*x/10,x>1/3,3*(1-x)/20); g:=x->x*cos(x); for n from 1 to N do b[n]:=(2/L)*int(f(x)*sin(n*Pi*x/L),x=0..L); d[n]:=(2/L)*int(g(x)*sin(n*Pi*x/L),x=0..L); end do: |
| > | # solution u(x,t): click on figure, then go to "Animation" and click on "Play" |
| > | u:=(x,t)->sum(
sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L) + (L*d[m]/(m*Pi*C))*sin(m*Pi*C*t/L)
), m=1..N); with(plots): animate( u(x,t), x=0..L, t=0..T, frames=50); |
| > |
| > | # example 2: |
| > | # the
example plots solution of wave equation # the initial data: u(x,0)=f(x), u_t(x,0)=g(x) # L:=Pi; C:=1; T:=2*Pi; N:=20; f:=x->piecewise(x<1/3,3*x/10,x>1/3,3*(1-x)/20); g:=x->0; ## g:=x->x*cos(x); for n from 1 to N do b[n]:=(2/L)*int(f(x)*sin(n*Pi*x/L),x=0..L); d[n]:=(2/L)*int(g(x)*sin(n*Pi*x/L),x=0..L); end do: u:=(x,t)->sum( sin(m*Pi*x/L)*(b[m]*cos(m*Pi*C*t/L) + (L*d[m]/(m*Pi*C))*sin(m*Pi*C*t/L) ), m=1..N); with(plots): animate( u(x,t), x=0..L, t=0..T, frames=50); |
| > |