Translating (Transforming) a recursive function

AI Thread Summary
The discussion revolves around transforming a recursive function to compute values in a sequence while adjusting for array indexing. The user is trying to rewrite the equation and initial conditions to accommodate negative indices, shifting the function definitions accordingly. They express confusion about how the shifts in the function and initial values relate mathematically, particularly when transitioning from k to k'. A suggestion is made to let the program handle the shifts automatically, which may involve modifying the equation to account for the new indexing. The user is implementing this in MATLAB and seeks clarification on the formal approach to achieve the desired results.
fred4321
Messages
4
Reaction score
0
Hi,

I am having trouble understanding how this works.

I am giving the following:
y[k+2] - y[k+1] + 0.24y[k] = f[k+2] - 2f[k+1];

y[-2] = 1, y[-1] = 2;

f[k] = 0 for k < 0;
f[k] = k for k >= 0;

I would like to have a program compute the next values in the sequence, so, I need y[-2] = 1 to become y[1] = 1 and y[-1] = 2 to become y[2] = 1 (so that the array indexing works, e.g., I can access a negative location of an array).

I let k' = k + 1 so that I'd get:
y[k'+3] - y[k'+2] + 0.24y[k'+1] = f[k'+3] - 2f[k'+1];
Then I made:
f[k] = 0 for k < 0;
f[k] = k for k >= 0;
become
f[k'] = 0 for k' < 3;
f[k'] = k for k' >= 3;
and
y[-2] = 1, y[-1] = 2;
become
y[1] = 1, y[2] = 2;

So now I have:
y[k'+3] - y[k'+2] + 0.24y[k'+1] = f[k'+3] - 2f[k'+1];
f[k'] = 0 for k' < 3;
f[k'] = k for k' >= 3;
y[1] = 1, y[2] = 2;

And now when I let k = 0, k[3] gives me the value that k[0] gave me in the old equation, which is exactly what I want.

My issue is, I don't understand how, mathematically, this works. For example, I don't understand how I went from:
f[k] = 0 for k < 0;
f[k] = k for k >= 0;
to
f[k'] = 0 for k' < 3;
f[k'] = k for k' >= 3;

if k' = k + 1.

It seems as though I've shifted the equation (y[k+2] - y[k+1] + 0.24y[k] = f[k+2] - 2f[k+1];) over by 1 unit in the positive x direction; however, I've shifted the initial values (y[-2] = 1, y[-1] = 2;) and the f's restrictions (k < 0; and k >= 0) over by 3 units.What I'm thinking is:
The original question should be:
f[k'] = 0 for k < k[0];
f[k'] = k for k' >= k[0];
y[k[0]-2] = 1, y[k[0]-1] = 2;

What would be the correct, more formal approach to achieving what I want. Also, should the original question be as I've written above?

I'm pretty sure that the equation, as it's give, only produces the 'correct' answer, when k[0] = -2.

Thank you for your time, I realize that this question is rather lengthy.
 
Last edited:
Mathematics news on Phys.org
You simply shouldn't worry about "f(k) for k< -3" at all. Include, in your program,
"Double f(Double x)
{
Double y= 0;
if (x>= 0) y= x;
return y;
}
and let the program handle shifts.
 
Thanks for the reply. What do you mean by, "let the program handle the shift"?

Do you mean by changing adding k+n to the original equation so that it works out?

Also, I know that I didn't say, but I'm actually doing this with MATLAB, I don't think that makes a difference. On know C++ though so I understand your code.
 
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Thread 'Imaginary Pythagoras'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Back
Top