How do I algorithmically generate the nth term of this sequence?

  • Thread starter Thread starter FrankDrebon
  • Start date Start date
  • Tags Tags
    Sequence
Click For Summary

Discussion Overview

The discussion revolves around generating the nth term of a sequence derived from an input vector of size n, where each term is a sum of products of n-1 components of the vector. Participants explore algorithmic approaches for computing this term, particularly in the context of MATLAB scripting.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes the sequence as a sum of products of n-1 components from an input vector of size n, seeking an algorithmic method to generate the nth term.
  • Another participant suggests a method involving the total product of all coefficients, proposing a summation approach that excludes one coefficient at a time, with considerations for handling zero coefficients.
  • A further suggestion includes a nested loop approach for cases where coefficients may be zero, emphasizing the need for conditional handling in the algorithm.
  • Another participant proposes an explicit formula for the function, which relies on the assumption of non-zero components and discusses the implications of having zero coefficients on the function's behavior.

Areas of Agreement / Disagreement

Participants generally agree on the approach to generating the nth term algorithmically, but there are differing views on the handling of zero coefficients and the applicability of the proposed explicit formula. The discussion remains open regarding the best method to implement.

Contextual Notes

Limitations include the assumption that coefficients are non-zero for certain proposed methods, and the implications of having zero coefficients are not fully resolved.

FrankDrebon
Messages
9
Reaction score
0
Hi all,

I have a term in an equation that grows in an intuitive manner each time I increase the number of variables.

Basically, for an input vector of size n, this term is a sum of n terms, each of which is a product of n-1 components in the vector. Put simply, it is the sum of each unique way that the components of the vector can be multiplied together as a product of n-1 components.

I've probably explained that badly, so the first few terms can be found in the image below:

http://img52.imageshack.us/img52/1779/cvalues.jpg

It is fairly easy to compute the next term myself. However, I'd like to be able to find an algorithm for generating the nth term for inclusion in a MATLAB script.

Essentially the problem boils down to "how do I generate the nth term algorithmically?" I've run out of ideas, but can't help but think there would be some (relatively) simple matrix operation that could generate this. Maybe the pattern-hunters amongst you will notice something I haven't.

Any thoughts or suggestions welcome!
 
Last edited by a moderator:
Physics news on Phys.org
FrankDrebon said:
Hi all,

I have a term in an equation that grows in an intuitive manner each time I increase the number of variables.

Basically, for an input vector of size n, this term is a sum of n terms, each of which is a product of n-1 components in the vector. Put simply, it is the sum of each unique way that the components of the vector can be multiplied together as a product of n-1 components.

I've probably explained that badly, so the first few terms can be found in the image below:

http://img52.imageshack.us/img52/1779/cvalues.jpg

It is fairly easy to compute the next term myself. However, I'd like to be able to find an algorithm for generating the nth term for inclusion in a MATLAB script.

Essentially the problem boils down to "how do I generate the nth term algorithmically?" I've run out of ideas, but can't help but think there would be some (relatively) simple matrix operation that could generate this. Maybe the pattern-hunters amongst you will notice something I haven't.

Any thoughts or suggestions welcome!

There is a trivially simple way to approach this. Notice that any term in your equation is the product of all coefficients (c(i), for i=1 ... n) with the exception of one. So, you can generate the total product of all coefficients (call it T), and then just do a summation over the terms, i.e. T/c(i).

In equation form this looks as follows:

T= product of all coefficients c(i) for i=1 ... n

[tex]A=\sum_{i=1}^n {{T}\over{c(i)}}[/tex]

So bascially you have two independent (i.e. not nested) loops. The first loop does the total product, and the second does the summation you are interested in. The only thing you have to worry about is cases where a coefficient is zero, but this is easily handled with some if statements.

If you expect no zero coefficients, then the above method is easy. If you expect cases with zeros, then you may prefer another approach as follows.

[tex]A=\sum_{i=1}^n \prod_{k \ne i} c(k)[/tex]

This is also easy, but now your two loops are nested. The outer loop does a summation and the inner loop does a product calculation, but always excludes one of the coefficients.
 
Last edited by a moderator:
Nice one! None of the coefficients should be zero, so I won't have to worry about that. Thanks a lot mate.
 
Hi, you can also find an explicit formula. If f is your function, T your product to begin with, and [tex]x_i[/tex] the components, you will have [tex]f^k(x_i)=T^{\frac{(n-1)^k-(-1)^k}{n}}x_i^{(-1)^k}[/tex] which can be proven inductively.

This will however only work when you originally have non-zero components. If you have more than one zero to begin with, [tex]f(x_i) = 0[/tex] for all i, and if you exactly one zero, say [tex]x_j[/tex], then [tex]f(x_i)=0[/tex] for all [tex]i \not = j[/tex], and [tex]f(f(x_i)) = 0[/tex] for all i, which is not a particulary interesting case.
 
Last edited:

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 24 ·
Replies
24
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K