I don't understand sigma notation and loop

I have a book that says that

enter image description here

and says this is equivalent to saying

for(i = 1; i <= N; i++) Sum += i; 

and he further says, using this simple formula,

enter image description here

since (maximum value - minimum value + 1)

and he says that changing this C code will

 for(k = j; k <= 1; k++) Sum += k; 

However, I seriously do not understand this! can someone explain this to me ?????

Many thanks

+7
algorithm for-loop
source share
7 answers

The second sum starts with k=j and ends with i . This sum is not equal to (j - i - 1) , instead it is equal to (i - j + 1) . Let's make an example:

If j = 3 and i = 6 , then k = 3 and sum = 1+1+1+1 = 4 . Using the formula: sum = (i - j + 1) = 6 - 3 + 1 = 4 .

Now, the C code for the first example, they said:

for (i = 1; i <= N; i ++) Sum + = i;

It is not right. Instead, it should be:

 for(i = 1; i <= N; i++) Sum += 1; 

In the second, they said:

for (k = j; k <= 1; k ++) Sum + = k;

Instead, it should be:

 for(k = j; k <= i; k++) Sum += 1; // Where i >= j 
+3
source share

If you do not understand the C code, this is due to errors in it.

In the first case, it should be 1 instead of i:

 for(i = 1; i <= N; i++) Sum += 1; 

It should be me instead of 1 and 1 instead of k in the second case:

 for(k = j; k <= i; k++) Sum += 1; 

PS Also you have mistypo in the formula itself. 1 for some reason is skipped after Sigma. and j and i are changing ...

What kind of book are you talking about?

+2
source share

Undoubtedly, this means that the amount is equivalent

 for (i = 1; i <= N; i++) Sum += 1; 

?

0
source share

It looks like the book just says for given x and y

 for (int i = x; i <= y; ++i) Sum += 1; 

looks like

and thus replacing x = 1 and y = N ,

 for (int i = 1; i <= N; ++i) Sum += 1; 

looks like

This, of course, is what you expect: when counting from 1 to N you count a total of N In the general case, when counting from x to y you count y - x + 1 items ( + 1 , since you include both borders).

0
source share

I think we have limitations for calculating For loops through Sigma notation

eg

 x=0 For i=2 to n-1 do For j=i+1 To n-2 do x=x+1 

for n = 5 we have x = 1

but when i calculate it by sigma

Sigma i = 2 - n-1 (Sigma j = i + 1 - n-2) = (n ^ 2 -7 * n + 10) / 2

if we substitute n = 5, then the answer is zero, why?

0
source share

I am by no means a tempting guru, just a layman, but perhaps the conditions of a layman will be useful to someone. Again, I'm not a guru, so scream if you notice errors. Anyway, let's just plug in and plug in the “loop” ...

Given the number on the right side of Sigma, we are told that this sum starts with 1, therefore

First iteration

Amount = 1 + 1

Second iteration

2 + 2

Third iteration

4 + 3

Fourth iteration

7 + 4

until limit where you will have

SumBeforeLast + N

What is the Limit? Well in C you would define it as (i = 1; i <= N;). In English, if N is 100, then the Limit will be "where I = 100". If N = 5, then the "Limit" is "where i = 5", etc.

If you want to be pedantic (and you should), you can also say that Limit has two parts, I have the initial value when I “run” the “run” (Lambda Calculus does not apply to calculating either time or machine, but you can always delete this model, as soon as you get the concept), this is the "lower limit", and the "final value" is the "upper limit".

Do you want to know the "magic" of derivatives? It is difficult to explain, but basically, sometimes, sometimes sometimes, when N = Infinity or some other meaning, and again just SOME, if the algebra is arranged so that the produced algebra cancels itself, we are left with a new simplified algebra that is no longer takes "infinite" or "iterations" to achieve some desired result. The search for these “derivatives” is a huge part of both mathematics and algorithm development.

In other words, the “magic” of Calculus is nothing more than a Sigma operation that creates a pattern like (x / x) * someEquation combined with the fact that something (like (x / x)) divides by itself equals 1, and the fact that 1 multiplied by "someEquation" does not change "someEquation", which means that large parts of the equation are not needed to calculate the Sigma operation at some iteration.

Keep in mind that if we discard x / x or rather just x, then all complexity will be discarded with its discreteness or even infinity, in which case completely new calculations can be not only optimized, but simply made possible for our limited hardware.

I have little experience with this, but as I understand it, derivative development algorithms are used to optimize algorithms because they extract complexity from the recursive series. Sometimes these optimizations bring problems of infinite complexity to the finite, which makes them solvable by computers, which, in the end, have finite living spaces and resources and therefore are limited by finite or discrete mathematics.

The integral, on the other hand, while it increases the complexity of the integral function, is fundamental to discovering many new algorithms, especially those that have complexity that goes beyond our ability to discover, using only our intuition and raw mathematical reasoning.

0
source share

I created this while loop, which illustrates in detail sigma note elements.

 //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 limit } System.out.println("Sigma Answer: " + finalAnswer); //Prints the final sum of the "Sigma" } } 

Thus, this application will simulate a sigma of 100 Σ n + 5 n = 0 . The application works by creating the previous and current sequence based on sigma and adding both the current and previous sequence together until the sigma limit is reached to calculate the total number returned by the sigma. Thus, the sequence {5 + 6 + 7 + 8 + 9 + 10.11 +. ,, 105} will be added at all.

0
source share

All Articles