How to compute for a sequence for a given value in wolfram?

53 Views Asked by At

What would be the correct input in the wolfram website to give u(n) for a given n, where u is a sequence ?

Something like:

evaluate [u(n+1)=27*u(n)-14, u(0) = 1] at n = 3
1

There are 1 best solutions below

0
On BEST ANSWER

The comments already discussed how you can manipulate the recurrence. - But if you are not satisfied with that, why not use the Mathematica cloud interpreter in the wolfram lab?

  • There are two ways to do this. The direct one is to open the code of your wolfram query:

$1.$

enter image description here

$2.$

  • Which will lead you to the computable notebook, and after you scroll down a bit, you'll find the code:

enter image description here

$3.$

  • Where for example I told it to get me the terms from $4$th to $6$th. After running that code section (Either clicking Run or pressing Shift + Enter), you will get your results instantly:

enter image description here


What if "Open code" is not available?

However, if you can't directly open the code of your wolfram query, you can go and open a new notebook and paste that code there.

You navigate to programming lab and click "Start programming now". Then click File and New notebook.

Click on (+) sign and select "Wolfram language input". Now type in the code from the lab:

RecurrenceTable[{a[0] == 1, a[1 + n] == -14 + 27 a[n]}, a, {n, 4, 6}]

Modify the {n, 4, 6} part to list the terms you want, and the {a[0] == 1, a[1 + n] == -14 + 27 a[n]} part to setup your recurrence.

Then either click the gear icon on the right and select "Evaluate", or press Shift+Enter.

You'll get your output:

{245281,6622573,178809457}

Bonus points, if you want to quickly change the starting condition, you can make a table:


A code snippet to help with your example

You can use the following code:

ClearAll[recurrence,a]
recurrenceName = a;
recurrence[x_] := {a[0] == x, a[1 + n] == -14 + 27 a[n]}
a0min = 0;
a0max = 3;
nmin = 0;
nmax = 5;
Grid[Prepend[Transpose[Prepend[Transpose[Table[RecurrenceTable[recurrence[x], recurrenceName, {n, nmin, nmax}],{x,a0min,a0max}]],Table[StringForm["a(0) = ``", a],{a,a0min,a0max}]]],Table[If[n<nmin,"",StringForm["n = ``", n]],{n,nmin-1,nmax}]],Frame->All]

To instantly generate a table for all values you need:

enter image description here