Question
We saw that the complexity of matrix-vector multiplication is O(n2). Use your mat_vec_gen(n) function and record the time needed to multiply an nn matrix by
We saw that the complexity of matrix-vector multiplication is O(n2). Use your mat_vec_gen(n) function and record the time needed to multiply an nn matrix by a vector of length n, for n sizes = [10,20,40,80,160,320,640,1280,2560,5120,10240]. Store these timing estimates in a list (say, timing). Create a plot of the matrix sizes (sizes) on the horizontal axis versus the run-times to perform the multiplications (timing) on the vertical axis. Be sure to label your axes! Include a print-out of this plot with your assignment. Write a sentence or two about whether or not the shape of this plot matches your expectations based on the complexity of matrix-vector multiplication.
mat_vec_gen(n) is:
from random import randint def mat_vec_gen(n): [[randint (1,100) for ii in range(n)] [randint (1,100) for 11 in range (n)] -A for JJ in range(n)] -"x = result- for i in range(n) total = 0 for j in range(n): -, total +=A[i][j] *x[j] result.append (total) return A, xStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started