Mathematica: Recursive expression

  • Context: Mathematica 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Expression Mathematica
Click For Summary
SUMMARY

The discussion focuses on constructing a recursive function in Mathematica to evaluate the infinite continued fraction defined as $$ F = \frac{a_1}{1+\frac{a_2}{1+\frac{a_3}{1+a_4}}} $$, where \( a_n = n \). The user attempts to define the function using the syntax `f[n_] := n;` and `f[n_] := (f[n - 1]) /.Subscript[a, n - 1] :> Subscript[a, n - 1]/(1 + Subscript[a, n])`. The goal is to propagate the function up to \( a_1 \) for a given \( n \). The provided solutions are aimed at achieving this recursive evaluation.

PREREQUISITES
  • Understanding of recursive functions in Mathematica
  • Familiarity with continued fractions
  • Basic knowledge of Mathematica syntax and functions
  • Concept of substitution in expressions using Mathematica
NEXT STEPS
  • Explore advanced recursive function techniques in Mathematica
  • Learn about continued fractions and their applications in mathematics
  • Investigate the use of `ReplaceAll` in Mathematica for expression manipulation
  • Study examples of recursive definitions in Mathematica for complex mathematical constructs
USEFUL FOR

Mathematics students, Mathematica users, and anyone interested in recursive function development and continued fractions.

Niles
Messages
1,834
Reaction score
0
Hi

I am trying to find a smart way to write the following fraction,

$$
F = \frac{a_1}{1+\frac{a_2}{1+\frac{a_3}{1+a_4}}}
$$

Here we can just take [itex]a_n= n[/itex] for simplicity. My fraction is in principle infinite, but I am trying to construct a function which can find [itex]F[/itex] for a given [itex]n[/itex] recursively. I haven't had much success. So far I have

f[n_] := n;
f[n - 1]/(1 + f[n])

which is the last term for a given [itex]n[/itex]. For do I propagate all the way up to [itex]a_1[/itex] then?
 
Physics news on Phys.org
Code:
f[1] = Subscript[a, 1];

f[n_] := (f[n - 1]) /.Subscript[a, n - 1] :> Subscript[a, n - 1]/(1 + Subscript[a, n])
Does that work?
 

Similar threads

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