Simplifying a recursive function

In summary, the conversation discusses finding a formula for the function f(x) = a*f(x-1) + b*f(x-2) for x≥1, with known values for f(-1) and f(0). The individuals tried various methods, including plugging in values and using Mathematica, but ultimately used a substitution method to find a general solution for f(x) in terms of the given parameters.
  • #1
randommacuser
24
0
I am trying to find a formula for f(x) = a*f(x-1) + b*f(x-2) for x≥1, assuming f(-1) and f(0) are known. In other words, I need some expression for f(x) just in terms of a, b, f(-1), and f(0).

I tried plugging in stuff and factoring on paper for the first few iterations, but it quickly got out of control. Then I let Mathematica do the grunt work and tried to see some patterns as x increases. But so far I am only seeing the obvious first couple of terms: a^x * f(0) - (x-1) * a^(x-1) * b * f(0)

Any clues? Should I even be doing the problem this way, or is there some simpler method?
 
Last edited:
Physics news on Phys.org
  • #2
just a question...the function is x and the variable is n?
 
  • #3
Well, that was the way the problem was stated. I've edited the OP to make it more standard. Now f is a function of the variable x, as usual.
 
  • #4
hey man did u try to get f(1) and then replace it in f(2) and so on u will find a relation between f(2) with just f(0) and f(-1) in it with some factorize and like that ... try it
 
  • #5
Try substituting [itex]f(x) = m^x[/itex] for some m, and see where that gets you (this is a standard method for solving homogeneous constant coefficient linear recurrences. It's analogous to solving homogeneous constant coefficient linear ODEs using an exponential substitution).
 
Last edited:
  • #6
moe_3_moe: Yes, I did this by hand to about f(5) and on Mathematica to f(10). But the goal is one expression of f(x), for all x, in terms of the four given parameters.
 
  • #7
ok get it ... let's see what we can do ... at least now we know how mathematica works hard lol ...
 
  • #8
data...can we have more details about ur suggestion
 
  • #9
Using that substitution you can find the values for m that give you solutions. There will be two of them. The general solution is a linear combination of the two; use the given values for f(0) and f(-1) to find the particular solution.
 
  • #10
right thanks ..it did work ...
 
  • #11
Perfect. Thanks for your help, Data.
 

What is a recursive function?

A recursive function is a function that calls itself repeatedly until a specific condition is met. This allows for solving complex problems by breaking them down into smaller, simpler parts.

Why is simplifying a recursive function important?

Simplifying a recursive function is important because it can improve the efficiency and readability of the code. It reduces the number of function calls and makes it easier to understand and debug the code.

What are some common techniques for simplifying a recursive function?

Some common techniques for simplifying a recursive function include using a base case to end the recursion, using tail recursion to optimize the function, and using memoization to store previously calculated values.

How can I test and debug a recursive function?

You can test and debug a recursive function by using print statements or a debugger to track the function calls and the values of variables. It is also helpful to use smaller input values to track the flow of the function.

What are some potential pitfalls to be aware of when simplifying a recursive function?

Some potential pitfalls to be aware of when simplifying a recursive function include infinite recursion, incorrect base cases, and incorrect implementation of recursive calls. It is important to thoroughly test and debug the code to avoid these issues.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
271
  • Calculus and Beyond Homework Help
Replies
10
Views
861
  • Calculus and Beyond Homework Help
Replies
3
Views
274
  • Calculus and Beyond Homework Help
Replies
2
Views
460
  • Calculus and Beyond Homework Help
Replies
1
Views
142
  • Calculus and Beyond Homework Help
Replies
1
Views
760
  • Calculus and Beyond Homework Help
Replies
7
Views
953
  • Calculus and Beyond Homework Help
Replies
8
Views
466
  • Calculus and Beyond Homework Help
Replies
2
Views
537
  • Calculus and Beyond Homework Help
Replies
9
Views
753
Back
Top