Question: strange error using pdsolve with numeric option when range uses Pi for length

When solving this 1D wave PDE numerically, if the range used is -Pi..Pi then I get this error

sol:-plot(t=0,numpoints=100);
Error, (in Vector) unable to store '-Pi' when datatype=float[8]

When trying to plot the solution. Changing the range to -1..1 the error goes away.

I would expect the numerical solver to handle these things automatically? 

Please see attached worksheet.   How to work around this if one wants to use range from -Pi..Pi?

 

#wave PDE with periodic BC.
restart;

pde := diff(u(x,t),t$2)=diff(u(x,t),x$2);
bc  := u(-Pi,t)=u(Pi,t),D[1](u)(-Pi,t)=D[1](u)(Pi,t);
f:=x->piecewise(-Pi/2<x and x<Pi/2,1,true,0);
plot(f(x),x=-Pi..Pi);
ic  := u(x,0)=f(x),D[2](u)(x,0)=0;
sol:=pdsolve(pde,{bc,ic},u(x,t),numeric,time=t,range=-Pi..Pi)

pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)

bc := u(-Pi, t) = u(Pi, t), (D[1](u))(-Pi, t) = (D[1](u))(Pi, t)

f := proc (x) options operator, arrow; piecewise(-(1/2)*Pi < x and x < (1/2)*Pi, 1, true, 0) end proc

u(x, 0) = piecewise(-(1/2)*Pi < x and x < (1/2)*Pi, 1, 0), (D[2](u))(x, 0) = 0

_m1174810042944

sol:-plot(t=0,numpoints=100);

Error, (in Vector) unable to store '-Pi' when datatype=float[8]

pde := diff(u(x,t),t$2)=diff(u(x,t),x$2);
bc  := u(-1,t)=u(1,t),D[1](u)(-1,t)=D[1](u)(1,t);
f:=x->piecewise(-1/2<x and x<1/2,1,true,0);
plot(f(x),x=-1..1);
ic  := u(x,0)=f(x),D[2](u)(x,0)=0;
sol:=pdsolve(pde,{bc,ic},u(x,t),numeric,time=t,range=-1..1)

pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)

bc := u(-1, t) = u(1, t), (D[1](u))(-1, t) = (D[1](u))(1, t)

f := proc (x) options operator, arrow; piecewise(-1/2 < x and x < 1/2, 1, true, 0) end proc

u(x, 0) = piecewise(-1/2 < x and x < 1/2, 1, 0), (D[2](u))(x, 0) = 0

_m1174805392512

sol:-plot(t=0,numpoints=100);

 


 

Download solving_wave_pde.mw

Please Wait...