Function that consulates the energy sequence???

I usually always never post on forms because a quck Google search gets me the information I need.
This time its different... I need to create a function that consulates the " energy sequence "
Using this formula below:

https://postimg.org/image/4utc2mutn/

No one from my classmates knows how to deal with this one, and google doesn't seem to have any answers either..
Can someone please point me to the right direction of figuring this out?
( I'm a stud first year, first semester at computer science ...)
Last edited on
So what have you tried on your own? Not trying to be cruel here, but you'll get a better response if you have at least shown where you have attempted to code whatever it is on your own. Surely, the instructor has given you something to go on.
Last edited on
I don't even understand the mathematical formula... All I'm asking is for someone to explain the formula by words...
It looks like you are not posting the whole problem - with your image alone it is not clear what is meant by the "sixth function" and "seventh function".

However ... from what is given, it looks like you have to write a function that takes as input:
L: the length of the sequence;
s[]: an array of length L, each of whose members is either -1 or +1.

You can then calculate arrays
C_k = summation formula; e.g.
C_1 = s_1 s_2 + s_2 s_3 + s_3 s_4 + ... + s_(L-1) s_L
C_2 = s_1 s_3 + s_2 s_4 + s_3 s_5 + ... + s_(L-2) s_L
.....
C_(L-1) = s_1 s_L

Then you can calculate the energy
E = C_1^2 + C_2^2 + ... C_(L-1)^2
and use E as the return value of the function.

It looks like everything is an int. Arrays in C++ start from 0, not 1, but I'm sure that you can work around that (probably by shifting the formulae "back" one number).

L and s[] are probably set outside of your function.

It looks vaguely like an atomic physics problem; not that that affects the computational aspect.
I'm not familiar with the formula, but I can try to explain what I understand from it.

A sequence is a set of numbers that follow a rule. (Think of it as an array.)
Si ϵ {+1, -1} means that the ith number in the sequence S can either be + or -1. This is our rule. (I think, I've only read about sets on YouTube because I was bored one day.)

Σ is called sigma and is used as a shorthand of writing sum of.
1
2
3
10
Σ i
i = 1

This means the sum of the elements i, starting at 1 and going up to and including 10. In other words, it is the shorthand of writing 1 + 2 + 3 + 4 + ... + 9 + 10.

Similarly, E(S) is what we want to calculate. It is the energy of sequence S. But to calculate E(S), we need to calculate Ck(S).

To calculate Ck(S), we need L, the length of our sequence/array and k, which is a counter/iterator when we calculate E(S).
Suppose we had the sequence
1
2
const int L{ 5 };
int S[L]{ -1, -1, 1, -1, 1 };

then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pretend arrays are 1-indexed
when k == 1
    C(S) == S[1]*S[1+1] + S[2]*S[2+1] + S[3]*S[3+1] + S[4]*S[4+1]
         == -1*-1 + -1*1 + 1*-1 + -1*1
         == 1 - 1 - 1 - 1
         == -2
    stop at 4, as L-k == 4
when k == 2
    C(S) == S[1]*S[1+2] + S[2]*S[2+2] + S[3]*S[3+2]
         == -1*1 + -1*-1 + 1*1
         == -1 + 1 + 1
         == 1
    stop at 3
etc..


Now to get E(S), you do the above up to and including k == 4, square(?) each C(S) and add them together. I'm not sure if C(S) meant to be squared, but I don't know what else it could be.
1
2
3
4
5
6
7
8
9
when k == 3
    C(S) == S[1]*S[1+3] + S[2]*S[2+3]
         == -1*-1 + -1*1
         == 1 - 1
         == 0
when k == 4
    C(S) == S[1]*S[1+4]
         == -1*1
         == -1

1
2
3
E(S) == (-2)2 + (1)2 + (0)2 + (-1)2
     == 4 + 1 + 0 + 1
     == 6


Thus, the energy of sequence S{ -1, -1, 1, -1, 1 } is 6.
Last edited on
square(?) each C(S) and add them together. I'm not sure if C(S) meant to be squared,


I have similar doubts to integralfx. Given where this problem is likely to have come from, "energy" would come from second-order terms in {s_i}, and squaring C_k would make all contributions to the "energy" 4th-order. (Mind you the counter-argument is, that if they weren't squared then there is a far quicker way of getting the "energy" than calculating all these "cross terms" C_k; so, I don't know.)

I think you need to check the given formulae with your teacher/lecturer/professor.
Last edited on
Topic archived. No new replies allowed.