Why isn't Mathematica giving me the desired output for this RSolve equation?

  • Context: Mathematica 
  • Thread starter Thread starter ehrenfest
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the output of the RSolve function in Mathematica when solving a recurrence relation. Participants are exploring why the output differs based on the input conditions and syntax used, focusing on the specific case of the Fibonacci sequence and its relation to the Lucas numbers.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports that using RSolve with the conditions a[1] == 1 and a[2] == 1 yields an unexpected output involving both Fibonacci and Lucas numbers.
  • Another participant suggests that the issue might be an off-by-one error and proposes testing with a[0] == 1 instead.
  • Some participants express uncertainty about the syntax used in the RSolve function, questioning whether it is correct.
  • A participant mentions that in their version of Mathematica, the same input yields the expected output of just Fibonacci[n].
  • Another participant notes that clearing global variables changes the output, raising questions about the local versus global scope of variables in Mathematica.

Areas of Agreement / Disagreement

There is no consensus on whether the output discrepancy is due to a bug, syntax issues, or the influence of global variables. Participants have differing experiences with the same RSolve input, indicating multiple competing views on the matter.

Contextual Notes

Participants mention different versions of Mathematica, which may affect the outputs. There is also uncertainty regarding the implications of using global variables and how they might influence the results of the RSolve function.

ehrenfest
Messages
2,001
Reaction score
1

Homework Statement


When I type
RSolve[{a[n] == a[n - 1] + a[n - 2], a[1] == 1 && a[2] == 1}, a[n], n]
into mathematica 6 why does it give me
{{a[n] -> Fibonacci[n] - C[2] Fibonacci[n] + C[2] LucasL[n]}}
and not just
{{a[n] -> Fibonacci[n] }}
?


Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
Could be an off-by-one. What does:
Code:
RSolve[{a[n] == a[n - 1] + a[n - 2], a[1] == 1 && a[0] == 1}, a[n], n]
give?
 
same thing.

Code:
{{a[n] -> Fibonacci[n] - C[2] Fibonacci[n] + C[2] LucasL[n]}}

I think its a bug.
 
Hmm, is the syntax you're using correct? (I'm not a mathematica user.)

Code:
RSolve[{a[n] == a[n - 1] + a[n - 2], a[1] == 1 , a[0] == 1}, a[n], n]
or
Code:
RSolve[{a[n] == a[n - 1] + a[n - 2] &&  a[1] == 1 && a[0] == 1}, a[n], n]
seem more consistent.
 
I tried it and it just gives {{a[n] -> Fibonacci[n] }} for me. Not sure why, my mathematica knowledge isn't that great, but like you said could just be a bug?
 
In Math'ca 6.0.1.0,

RSolve[{a[n] == a[n - 1] + a[n - 2], a[1] == 1 && a[2] == 1}, a[n], n]

gives

{{a[n] -> Fibonacci[n]}}

whereas

RSolve[{a[n] == a[n - 1] + a[n - 2], a[1] == 1, a[0] == 1}, a[n], n]
and
RSolve[{a[n] == a[n - 1] + a[n - 2] && a[1] == 1 && a[0] == 1}, a[n], n]

both give

{{a[n] -> 1/2 (Fibonacci[n] + LucasL[n])}}
 
Yes. You're right. I just did a Clear["Global`*"] and began getting the same answer as you. I am not really sure how why the Clear["Global`*"] would change the evaluation of this though...it seems like all variables should be local.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K