Nth and First n subparagraphs (Fibonacci sequence, matrix) of linear recursion of constant coefficients

Source: Internet
Author: User
Tags constant

(i) The fast method for the nth term of the Fibonacci sequence F[n]=f[n-1]+f[n-2],f[1]=f[2]=1 (without considering the high accuracy).

Solution:

Consider the 1x2 matrix "f[n-2],f[n-1]". Based on the recursive relationship of the Fibonacci sequence, we want to get the matrix "f[n-1],f[n" = "f[n-1],f[n-1]+f[n-2" by multiplying a 2x2 matrix.

It is easy to construct this 2x2 matrix A, namely:

0 1
1 1

So, there are "f[1],f[2" "xa=" f[2],f[3] "

And because matrix multiplication satisfies the binding law, there are:

"f[1],f[2]" xa n-1= "f[n],f[n+1]"

The first element of this matrix is the one that is being asked.

As for how to quickly find a n-1, I believe everyone will, that is, recursion: N is even when an= (a n/2) 2;n is odd, an= (a n/2) 2*a.

Problem (a) resolved.

(ii) The fast method for the nth term of the sequence f[n]=f[n-1]+f[n-2]+1,f[1]=f[2]=1 (without considering the high accuracy).

Solution:

In the following precedent, considering the matrix "f[n-2],f[n-1],1" of 1x3, we hope to obtain a 3x3 matrix A, which multiplies the matrix of this 1x3 by a: "f[n-1],f[n],1" = "f[n-1],f[n-1]+f[n-2]+1,1"

It is easy to construct this 3x3 matrix A, i.e.:

0 1 0
1 1 0
0 1 1

Problem (ii) resolved.

(iii) The fast method for the nth term of the sequence f[n]=f[n-1]+f[n-2]+n+1,f[1]=f[2]=1 (without considering the high accuracy).

Solution:

In the following precedent, consider the matrix "f[n-2],f[n-1],n,1" of the 1x4, hoping to obtain a 4x4 matrix A, so that the 1x4 matrix multiplied by a to get the matrix:

"f[n-1],f[n],n+1,1" = "f[n-1],f[n-1]+f[n-2]+n+1,n+1,1"

It is easy to construct this 4x4 matrix A, i.e.:

0 1 0 0
1 1 0 0
0 1 1 0
0 1 1 1

Problem (c) settlement ...

(iv) The fast method of finding the first N and S[n] of the sequence f[n]=f[n-1]+f[n-2],f[1]=f[2]=1 (without considering the high accuracy).

Solution:

Although we have s[n]=f[n+2]-1, but this article does not consider this method, we want to get a more general method.

Consider (a) The matrix A, which is easy to find we require "f[1],f[2" x (a+a2+a3+...+an-1). Many people use a very mathematical method to construct a 2r*2r (R is the order of a, here is 2) of the matrix to calculate, this method is cumbersome and very slow, this is no longer described here. A new approach is considered below.

Modelled on the previous idea, consider 1x3 's matrix "f[n-2],f[n-1],s[n-2", which we want to get 1x3 by multiplying a 3x3 matrix A:

"f[n-1],f[n],s[n-1]" = "f[n-1],f[n-1]+f[n-2],s[n-2]+f[n-1]"

Easy to get this 3x3 matrix is:

0 1 0
1 1 1
0 0 1

And then............ It is easy to find that the matrix size of this method is (r+1) * (r+1), much better than the previous popular method.

(v) The fast method of calculating the first n and S[n] of the sequence f[n]=f[n-1]+f[n-2]+n+1,f[1]=f[2]=1 (without considering the high accuracy).

Solution:

In combination (iii) (iv), it is easy to think of ...

Consider the Matrix "f[n-2],f[n-1],s[n-2],n,1" of 1x5,

We need to find a 5x5 matrix A so that it is multiplied by a to get a matrix of the following 1x5:

"f[n-1],f[n],s[n-1],n+1,1"

= "F[n-1", f[n-1]+f[n-2]+n+1,s[n-2]+f[n-1],n+1,1 "

Easy to construct a for:

0 1 0 0 0
1 1 1 0 0
0 0 1 0 0
0 1 0 1 0
0 1 0 1 1

And then...... Problem solving.

In general, if there is f[n]=p*f[n-1]+q*f[n-2]+r*n+s

You can construct the matrix A as:

0 Q 0 0 0
1 P 1 0 0
0 0 1 0 0
0 R 0 1 0
0 S 0 1 1

More generally, for F[n]=sigma (A[n-i]*f[n-i]) +poly (n), where 0<i<= a constant C, Poly (n) represents the polynomial of n, we can still construct a similar matrix A to solve the problem.

Set degree (Poly (n)) =d, and specify Poly (n) =0, D=-1, at this time corresponds to the constant coefficient linear homogeneous recursion relationship. The first n and the complexity of this method are:

((c+1) + (d+1)) 3*logns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.