Trying to solve 1D wave equation but not getting the plot correct

I am trying to solve the 1D wave equation. When I am trying to plot the approximated solution I am getting a straight line. Can anyone please check what is wrong with the plot command.
As I am unable to attach the edp file, I am pasting the code here.

// Problem definition
//1d pde on the boundary term u_t=u_{xx} 0<x<1, 0<t<1
// u(x,0)=sin(pi*x)
// u(0,t)=0,u(1,t)=0

verbosity=0;
macro uex(t) (sin(pi*x)exp(t))// Exact Solution
macro f(t) (sin(pi
x)exp(t)(pi^2+1))//Source Function

int nref=2;
real[int] L2error(nref); // initialize the L2 error array
real[int] Dx(nref); // initialize the space discretization array
real[int] DT(nref); // initialize the time discretization array

for(int n=0; n<nref;n++) {
int R=2^(n+3);// grid points on x-interval [0,1]
real h=1./R;
Dx[n]=h;
real dt=h^2;
DT[n]=dt;
real t, T=1;

// Technical data to recreate OX and OY axis
border OX(t=0,1){x=t;y=0;}
border OY(t=0,1){x=0;y=t;}

meshL Th=segment(R);

plot(Th, cmm="NO ADAPTED MESH ",wait=0);//,ps=“reactiondiffusionnoadapted2dmesh.eps”);
fespace Uh(Th,P1);

Uh u, v, uold;

u=sin(pi*x);// initial condition

problem Wave(u,v)=int1d(Th)(u*v/dt+dx(u)dx(v))
-int1d(Th)(uold
v/dt)
-int1d(Th)(f(t+dt/2.)*v)
+on(1,2,u=0);

// time loop
int m, M = T/dt;
for (m = 0; m < M; m++) {
uold=u;
Wave;
t+=dt;
plot(u,cmm=“Wave Equation Appox soln. u at time t=”+t,wait=0,value=1);
}// end of time loop

L2error[n]=sqrt(int1d(Th)(abs(u-uex(t))^2));
cout << "L2 error " << L2error[n] << endl;

}// end of loop on n<nref

Hi,
The problem statement in the code appears to be incorrect for a 1D wave equation. The formulation shown corresponds to the weak form of a parabolic equation, such as the heat equation. For the linear wave equation with a wave speed of 1, the correct weak form should involve dx(u)*v. I have made the necessary correction and attached the updated version. Please let me know if my understanding is incorrect.
trial.edp (1.5 KB)

Hi,
This code is not working as the error started increasing. For my code I was getting the correct error. I was having the problem in the plot of the approximate solution. While plotting the solution I am getting a straight line which should not happen because exact solution is a sine function. Please let me know if anything wrong with the plot command for 1D problem.

Hi,
please check the code i am getting a sine function as output and the error is also decreasing. But i am not sure if this is the weak form for a 1D wave equation
trial.edp (1.4 KB)

The plot command as you write is not supposed to work for 1d.
Instead you can do as

real[int] xx(R+1),yy(R+1),yyexact(R+1);
Uh uexe=uex(t);
for (int i=0;i<R+1;i++)
{
xx[i]=i*1./R;
yy[i]=u[](i);
yyexact[i]=uexe[](i);
}
plot([xx,yy],[xx,yyexact],wait =0,bb=[[0,0],[1,3]]);

But I don’t know how to plot the axis.

About your equation, you are solving the heat equation, not the wave equation.