0
$\begingroup$

Function: enter image description here

I am to solve for $T_{12}(4.8), T_{24}(1.2)$, using If and Which functions.

I started with this function and keep getting a recursion limit error:

t[n_] := (7/2 x) t[n - 1] - (7/2) t[n + 1]
$\endgroup$
3
  • 1
    $\begingroup$ RSolve may help. $\endgroup$ Commented Feb 10, 2020 at 10:53
  • $\begingroup$ because you haven't set a boundary condition. $\endgroup$ Commented Feb 10, 2020 at 12:46
  • $\begingroup$ It seems a duplicate question is posted. Please see my solution here. $\endgroup$ Commented Feb 10, 2020 at 14:15

3 Answers 3

1
$\begingroup$
T[x_, n_] := Block[{temp = n}, Which[
temp == 0, Return[1], temp == 1, Return[x], temp > 1, 
1/x T[x, temp - 2] - 2/7 T[x, temp - 1]]]

T[1, 4] gives

167/343

Or as what you want.

T[n_] := Block[{temp = n}, 
Which[temp == 0, Return[1], temp == 1, Return[x], temp > 1,
1/x T[temp - 2] - 2/7 T[temp - 1]]]
T[4] /. x -> 1
$\endgroup$
0
$\begingroup$

Try

T[0] = 1;
T[1] = x;
T[n_] := (1/x) T[n - 2] - (2/7) T[n - 1];
$\endgroup$
1
  • 1
    $\begingroup$ I would recommend T[n_] := T[n] = (1/x).... Without memoization, this recursion is going to be awfully inefficient. $\endgroup$ Commented Feb 10, 2020 at 14:13
0
$\begingroup$

Try

Clear[T, n, x]
Tn = T[n] /. RSolve[{T[n + 1] == 1/x T[n - 1] - 2/7 T[n], T[0] == 1, T[1] == x}, T, n][[1]]

Tn /. {n -> 12, x -> 4.8}

(* -0.0153785 *)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.