View the step-by-step solution to:

Use the idea of Binary Powering to write a python program which can calculate the nth power of a 2x2 matrix A.

Use the idea of Binary Powering to write a python program which can calculate the nth power of a 2x2 matrix A. You should ask the user to input the 4 numbers in A, and then to input the requested power n. Your program should have two functions:

1.One which will just multiply two matrices and give the result. The 2x2 matrices can be represented simply as lists of lists.
2.A recursive function that takes two (2) arguments, the matrix and the exponent.
(Hint: Remember the idea in binary powering is to re-write An (or in python notation, say the function binPow(A,n)) as
1.A*An-1 (or A*binPow(A,n-1)) if n is odd.
2.(A2)n/2 (or binPow(A*A,n/2)) if n is even.

Then use the idea that binPow(A,1) is just A to terminate the recursion). Test your program by calculating
1.The 8th power of [[2,1],[-2,-4]]
2.The 17th power of [[1,2],[1,-1]]
Sign up to view the entire interaction

Top Answer

Please see the Python program.... View the full answer

matrixPower.py

def matrixMult(A, B):
rows_A = len(A)
cols_A = len(A[0])
rows_B = len(B)
cols_B = len(B[0])
if cols_A != rows_B: #check to see if you can multiply the matrices
print "Cannot multiply the two...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online