I don't understand the sigma notation and for loop

后端 未结 7 570
忘掉有多难
忘掉有多难 2021-01-05 04:10

I have the book saying that

\"enter

and says that this is equivalent to saying

7条回答
  •  隐瞒了意图╮
    2021-01-05 04:21

    I created this while loop illustrating sigma notation elements in detail.

    //Illustrates how loops are similar to Sigmas in Math
    //This is equal to:
    //100
    //Sigma x+5
    //x=1
    
    package justscratch;
    
    public class SigmaCalculatorWhileLoop {
        private static int initial = 0; //Initial. Will increment by one until it reaches limit.
        private static final int limit = 100; //Limit
        private static final int incr = 5; //Number Incremental
        private static int pass = 0; //Will illustrate the current pass
        private static int tempAnswer = 0; //The previous sum
        private static int finalAnswer = 0; //The current sum
    
        public static void main(String[] args) {
            while(pass<=limit) {
                System.out.println("Pass: " + pass); //Prints out current Loop Pass
                System.out.println(tempAnswer); //Prints out the sequences generated by each iteration from the "sigma"
                tempAnswer = initial + incr; //Creates a new increased sequence until the limit is reached
                finalAnswer = tempAnswer + finalAnswer; //Adds the previous sequence with the current sequence
                pass++; //Increases the current pass
                initial++; //The initial value will increase by 1 until it reaches it's limit
            }
            System.out.println("Sigma Answer: " + finalAnswer); //Prints the final sum of the "Sigma"
        }
    }
    

    In summary, this app will simulate the sigma 100 Σ n+5 n=0. The app works by generating a previous and current sequence based on the sigma, and adding these both the current & previous sequence together until the sigma limit is reached to calculate the total returned by the sigma. So the sequences {5+6+7+8+9+10,11+. . . . 105} will be added altogether.

提交回复
热议问题