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?

3
  • 1
    are you asking if all your statements are run each pass in a loop? Yes, of course they are. Commented Nov 14, 2014 at 0:51
  • "Does a variable initialized in a for loop get reset every iteration?" YES! (unless you introduce a static variable) Commented Nov 14, 2014 at 1:02
  • You could have determined this yourself with a very simple experiment. Commented Nov 14, 2014 at 1:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.