# How to save some variables ( not all )

suppose i have a function

a[x_]:=a[x-1]+a[x-2] ;a[1]=a[0]=0


and i want to save the value a[2] (not all a[2],a[1],a[0] like using Dumpsave because by doing that my pc will run out of ram at some point.) How could i do that ?

(* the reason why Shift+Enter is not a choice is there are many a[ ]s and the function is not as simple as this so it will be much faster if i could store all value of a[ ]s in last calculation. ) ((Sorry for very bad English)

this is my problem i have these inputs

a[n_, m_, i_] :=
a[n, m, i] = (1/4) (a[n + 1, m, i - 1] + a[n - 1, m, i - 1] +
a[n, m + 1, i - 1] + a[n, m - 1, i - 1])

a[n_, m_, 0] := a[n, m, 0] = Mod[n, 100] Mod[m, 100]


the first code tells you that the value of a[m,n,i] comes from all its neighboring points but at difference time (i)

the second code tells you about the initial condition of each a[m,n,0]

if i want to fine a[1,1,10000] i cant run it in one time because my pc will run out of memory. So the way i do is by 1.finding all values of a[m,n,100]s and store all these values in a variable(which i name it to be a100) 2.starting new nb. and writing those two code(above) down 3.importing all values from a100 to each a[m,n,100] 4.replacing 0 in the second code with 100 ( to make new initial condition) 5.run the first code but this time the value of i will be 200

I tried to write down all these actions(1-5 above) in a new nb. and then just run each line from the start till the end but doing this takes too much time and i have to do it manually. So i wonder is there i way to run each line automatically from the start or is there a way to collect the all the values of all a[m,n,100]s faster than these or is there a way to find a[1,1,10000] fast

With the given initial conditions (a[1] = a[0] = 0), a[x] is zero for all x

RSolve[{a[x] == a[x - 1] + a[x - 2], a[1] == a[0] == 0}, a[x], x][[1]]

(*  {a[x] -> 0}  *)


Changing the initial conditions to a[1] = 1; a[0] = 0;

RSolve[{a[x] == a[x - 1] + a[x - 2], a[1] == 1, a[0] == 0}, a[x], x][[1]]

(*  {a[x] -> Fibonacci[x]}  *)

% // FunctionExpand // FullSimplify

(*  {a[x] -> ((1 + Sqrt[5])^x -
(-1 + Sqrt[5])^x*Cos[Pi*x])/
(2^x*Sqrt[5])}  *)


Fibonacci[x] encapsulates the value of a[x] for all real x; consequently, you need only save the expression Fibonacci[x] to save a[x] for all real x

Plot[Fibonacci[x], {x, -5, 5}]


• sorry for not stating my problem clearly... actually, there are three arguments in a[] which is a[m,n,i] and the value of a[m,n,i+1] is the mean value of all neighboring points around a[m,n,i] ( such as a[m,n+1,i] ,a[m+1,n,i ) . The problem is i want to store all a[m,n,i] (not a[m,n,i-1] for any (m,n) ) because i only need a[m,n,i] to compute a[m,n,i+1] – Surayuth Pintawong Jul 25 '17 at 6:10
• @SurayuthPintawong Please update your question with a minimal self-contained example. – Mr.Wizard Jul 25 '17 at 7:19