Adjusting terms number

32 Views Asked by At

I have equation with default $4$ terms but number of terms are related to input

for example :

Say the equation is $X - x^2 + x^3 - x^4$

If my input was $1$ then the equation equals $X$

If it was $2$ equation equals $X - x^2$ .

If it was $3$ then equation will equal $X- x^2 +x^3$ and so on.

I thought of making equations that have same result (say $1$) for specific numbers like (say $3$, $4$) and results zero for $2$ so I can put this equation on the second term and so on with other terms but how to make such an equation?

Is there a mathematical way to do that

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

You can define $f(n)=X-\sum_{i=2}^n (-1)^{i-1}x^i$ Having the upper limit of the sum depend on $n$ can make the number of terms depend on $n$.