Dear all;

Please give me few minutes to correct the output of this procedure.Many thinks.

We will solve the waves equations: diff(f(x,y,t),t$2)=c^2*( diff(f(x,y,t),x$2) +diff(f(x,y,t),y$2)); where (x,y,t) in [0,1]*[0,1]*[0,T] using finite difference. With Initial boundary conditions: [u(0,y,t)=u(1,y,t)=0], [u(x,0,t)=u(x,1,t)=0], [u(x,y,0)=f(x,y), diff(u(x,y,0),t)=g(x,y)]... The code is done and perfect but....The output of this procedure is Nothing. How can I plot the solution...

f:=(x,y)->x*(x-1)*y*(y-1);

g:=(x,y)->0;

analytical_sol:=proc(dx,dy,dt,Tf)

local Ft, Fx,Fy,x,y, c1,c2,c,j,k,i,u;

Ft := floor(Tf/dt)+1;

Fx := floor(1/dx)+1;

Fy := floor(1/dy)+1;

x:=[seq(0..1,dx)]:

y:=[seq(0..1,dy)]:

c1 := (c*dt/dx)^2;

c2 := (c*dt/dy)^2;

#Initial position

for j from 1 to Fx do

for k from 1 to Fy do

u[j,k,1] := f(-dx + j*dx, -dy + k*dy) -dt*g(-dx+j*dx, -dy + k*dy);

u[j,k,2] := f(-dx + j*dx, -dy +k*dy);

end do;

end do;

# Boundary values j=1

for i from 1 to Ft +1 do

for k from 1 to Fy do

u[1,k,i] := 0;

end do;

for k from 1 to Fy do

u[Fx,k,i] := 0;

end do;

for j from 1 to Fx do

u[j,1,i] := 0;

end do;

for j from 1 to Fx do

u[j,Fy,i] := 0;

end do;

end do;

for i from 3 to Ft + 1 do

for j from 2 to Fx-1 do

for k from 2 to Fy-1 do

u[j, k, i] := 2*u[j,k,i-1] - u[j,k,i-2] + c1*(u[j+1,k,i-1]-2*u[j,k,i-1]+u[j-1,k,i-1]) + c2*(u[j,k+1,i-1] - 2*u[j, k, i-1] + u[j,k-1, i-1]);

end do;

end do;

end do;

return Matrix([seq([seq([seq(u[i,j,k],i=1..Fx)],j=1..Fy)],k=1..Ft)]):

end proc:

## Try the test

f:=(x, y) -> x (x - 1) y (y - 1)

g:=(x, y) -> 0;

analytical_sol(0.1,0.1,0.1,2);