View Single Post
Old 05-18-2007, 10:40 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
It is not really tough once you see what you're really asking for.
Realize that X^k + X^k-1 + X^k-2 | k => 0
is the same as going backwards with k initialized with 0.
That's the first thing.

Second:
The invariant (the property that always remains the same) of
c*X^k == X^m
In normal words: this invariant implies that you only need to create an algorithm that calculates powers - basically!

Good news isn't it?

Let's see if I can create a quick implementation in some pseudo-language.

Code:
k=m; //user input
y=1;
WHILE k != 0 DO
  k=k-1;
  y=y-x;
END WHILE
In the WHILE loop, you add code to multiply with some constant which you have entered on the commandline. That's it!

A faster method for large numbers is available in terms of Horner.
I don't know anything about your mathskills with inequalities and summations. If the skills are there, then I can introduce you to it the formal way with easy to understand pseudo code.

Start playing with the pseudo code I gave you. Translate it into C++. Forget about classes and all the fancy stuff for now. See if you can get anything working.
__________________
Valmont is offline   Reply With Quote