0
for (i=0;i<=n;i++) {
       fsten[i]=fx(xsten[i]); //fsten[0] = fx(xsten[0]); fsten[1] = fx(xsten[1]); ...; etc. initializing the fsten array up to n times.
} //end of initial for loop

      y=0.0;

      for (i=0;i<=n;i++) {
       L=1.0; //the lagrange basis polynomial
           for (j=0;j<=n;j++) {
                if (i!=j) {
                 L=L*(x-xsten[j])/(xsten[i]-xsten[j]);
                } //end of if statement
           } //end of second for loop
       y=y+fsten[i]*L;
      }//end of first for loop

I am doing a Lagrange polynomial iteration. We are looking at the second for loop after the y=0.0. At the end of the for loop with the j=0, we have y = y+fsten[i]*L where L is obviously not 1 anymore. But when it goes to i=1 does that mean that the L=1.0 is true again?

1 Answers1

1

Yes it is true again, because you run the body of the loop again and L = 1.0 does set the variable L to 1.0.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182