Solve a recurrence

2014-03-14
2014-03-18
  • daviodan daviodan

    How to define:  f(n)=f(n-1)+f(n-2), f(1)=1, f(2)=2  ?

     
  • Aleksas

    Aleksas - 2014-03-18

    One of the many ways:

    (%i1) A:matrix([1,1],[1,0]);
    (%o1) matrix([1,1],[1,0])
    (%i2) makelist(A^^k,k,1,10);
    (%o2) [matrix([1,1],[1,0]),matrix([2,1],[1,1]),matrix([3,2],[2,1]),matrix([5,3],[3,2]),matrix([8,5],[5,3]),matrix([13,8],[8,5]),matrix([21,13],[13,8]),matrix([34,21],[21,13]),matrix([55,34],[34,21]),matrix([89,55],[55,34])]
    (%i3) define(f(n),(A^^n)[1,1]);
    (%o3) f(n):=(matrix([1,1],[1,0])^^n)[1,1]
    (%i4) f(5);
    (%o4) 8
    (%i5) makelist(f(k),k,1,20);
    (%o5) [1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946]

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks