smail  
                (smail)
               
                 
                 
              
                  
                    September 22, 2025,  5:32pm
                   
                   
              1 
               
             
            
              I need to compute a convolution in 1d  \\int\_{0}^{t}g(t-s)u(s) ds  for simplicity I take g=u=\\exp(-s) , the exact convolution is  t \\exp(-t) . I tried to adapt the freedom code Convolution-Sample.edp to the 1D case, but the error approximation is large, as shown in the attached figure.
Attached here are
conv1d-v1.edp  (529 Bytes)
Convolution-Sample.edp  (1.5 KB)
the two codes and the figure.
             
            
               
               
               
            
            
           
          
            
              
                smail  
                (smail)
               
                 
              
                  
                    September 22, 2025, 11:02pm
                   
                   
              2 
               
             
            
              Note that when the function g has a small compact support,
see the attached figure  the result is the same that I obtained using chebfun/Matlab
the matlab result
             
            
               
               
               
            
            
           
          
            
              
                fb77  
                (François Bouchut)
               
              
                  
                    September 23, 2025,  1:19pm
                   
                   
              3 
               
             
            
              Hello, 
You need to take care of the domain of integration. Here is a correction
load "msh3"
load "Element_P3"
// Compute the convolution: (g*u)(t)= \int_{0}{t}g(t-s)u(s) ds
 
meshL Th=segment(200,[10*x]);
fespace Vh(Th,P3);
func g = (x>0)? exp(-x) : 0.;
func u = (x>0)? exp(-x) : 0.;
func v = x*exp(-x);   // the exact convolution for u = g = exp(-s)
Vh vh=v;
Vh uh=u;
Vh gh=g;
func real  conv1d(real a) {  return int1d(Th)(gh(a-x)*uh); }
Vh convu = conv1d(x);
Vh xTh = x;
plot([xTh[],vh[]],[xTh[],convu[]], wait=true,cmm=" exact and approx u*g");
real err=sqrt(int1d(Th)((vh-convu)^2));
cout << " the L2 error is " << err << endl;
 
             
            
               
               
               
            
            
           
          
            
              
                smail  
                (smail)
               
              
                  
                    September 23, 2025,  1:51pm
                   
                   
              4 
               
             
            
              
I sincerely thank you, Prof. Bouchut, for your valuable help in identifying the error in my code. Your guidance was very helpful*.*
Best regards.