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

  • Mathematica
  • Thread starter ehrenfest
  • Start date
  • Tags
    Mathematica
In summary, when using Mathematica 6, there seems to be a bug where the output for the RSolve function may not always give the expected answer, particularly when using different syntax or when clearing all global variables beforehand.
  • #1
ehrenfest
2,020
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
  • #2
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?
 
  • #3
same thing.

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

I think its a bug.
 
  • #4
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.
 
  • #5
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?
 
  • #6
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])}}
 
  • #7
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.
 

1. What is a "Mathematica syntax problem"?

A Mathematica syntax problem refers to an error or issue with the coding language used in the Mathematica software. This can include incorrect formatting, missing or incorrect symbols, or other mistakes that prevent the code from running correctly.

2. How do I identify a syntax problem in my Mathematica code?

The Mathematica software has a built-in debugger that can help identify syntax problems. It will highlight any errors or warnings in the code and provide suggestions for how to fix them. Additionally, carefully reviewing the code and checking for common syntax mistakes can also help identify the problem.

3. What are some common causes of syntax problems in Mathematica?

Some common causes of syntax problems in Mathematica include typos, missing or incorrect symbols, mismatched brackets or parentheses, and using incorrect functions or arguments. It is important to carefully review the code and double check for these types of mistakes.

4. How can I fix a syntax problem in my Mathematica code?

If the debugger or manual review has identified a syntax problem, the code can be corrected by making the necessary changes. This may involve adding or removing symbols, correcting typos, or changing the formatting. It may also be helpful to refer to the Mathematica documentation or seek assistance from other users.

5. Are there any resources available to help with fixing Mathematica syntax problems?

Yes, there are several resources available to help with fixing syntax problems in Mathematica. The official Mathematica documentation provides detailed explanations and examples of proper syntax. There are also online forums and communities where users can ask for help and receive guidance from more experienced users. Additionally, there are books and tutorials available for learning Mathematica and improving coding skills.

Similar threads

Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
936
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
262
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top