title: gauss-legendre in c++
body: <p>i am trying to create gauss-legendre code according to the following  algorithm:</p>
  
  <p>for n points
  <img src="https://i.stack.imgur.com/VCebY.png" alt="for n points"></p>
  
  <p>That is,it is created a 2n equation system (if we demand to be accurate for polynominals of order 2n-1  , 
  <img src="https://i.stack.imgur.com/xksml.png" alt=""></p>
  
  <p>ti are roots of the legendre polynominals of order n.The legendre poynominals are given :<img src="https://i.stack.imgur.com/eMdM8.png" alt=""></p>
  
  <p>and wi : <img src="https://i.stack.imgur.com/FtOdg.png" alt=""></p>
  
  <p>My code is :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include &lt;cstdlib&gt;
  #include &lt;iomanip&gt;
  #include &lt;cmath&gt;
  
  
  using namespace std;
  
  const double pi=3.14;
  
  
  //my function with limits (-1,1)
  double f(double x){
  double y;
  y=(pi/4.0)*(log((pi*(x+1.0))/4.0 +1.0));
  return y;
  
  }
  
  double legendre (int n){
  
      double *L,*w,*t;
      double x,sum1,sum2,result;
      L=new double [n];
      w=new double [n];
      t=new double [n];
  
  
          while(n&lt;10){
  
           L[0]=1;
           L[1]=x;
  
  
          //legendre coef
          for (int i=1;i&lt;=10;i++){
          L[i+1]=((2.0*i+1.0)*x*L[i] - i*L[i-1])/(i+1.0);
  
  
          }
  
          //weights w
          w=0;
          for (int i=1;i&lt;=10;i++){
          w[i]+=(2.0*(1.0-x*x))/(i*i*(L[i-1]*L[i-1]));
          }
  
  
          //sums  w*t
          for (int i=1;i&lt;=10;i++){
              sum1=0.0; //for k=1,3,5,2n-1
              for (int k=1;k&lt;=2*n-1;k+=2){
                  sum1+=w[i]*(pow(t[i],k));
              }
                  sum1=0;
                  sum2=0.0;//for k=0,2,4,2n-2
                  for(int k=0;k&lt;=2*n-2;k+=2){
                      sum2+=w[i]*(pow(t[i],k));
                  }
                  sum2=2.0/n;
          }
  
  
      }
  
      result=w*f(*t);
  
      return result;
  
  }
  
  
  int main()
  {
      double eps=1e-8;//accuracy
      double exact=0.8565899396;//exact solution for the integral
      double error=1.0;
      double result;
  
      int n=1;//initial point
  
  
      while (fabs(result-exact)&gt;eps) {
          result=legendre(n);
          cout &lt;&lt;"\nFor n = "&lt;&lt;n&lt;&lt;",error = "&lt;&lt;fabs(error-exact)&lt;&lt;",value = "&lt;&lt;result;
  
      n++;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>My problems are:</p>
  
  <p>1) The compiler gives me :error: invalid operands of types ‘double*’ and ‘double’ to binary ‘operator*’       --> at   result=w*f(*t);</p>
  
  <p>2) I am not sure if i have done the whole thing right.I mean ,if i combined all the things together and if i implemented right the algorithm.</p>