Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The banded, upper triangular matrix A ERXn can be written as 1 01 C1 Clo bC3 n-2 On-2 Cn-2 an-1 bn-1 CU rl where a
The banded, upper triangular matrix A ERXn can be written as 1 01 C1 Clo bC3 n-2 On-2 Cn-2 an-1 bn-1 CU rl where a = (al , a2, . . . , an-2, an-i,an) E R", 1,02- ,0n-2, 0n-1 The entries of a, b, and c are all assumed to be nonzero (a) Write a pseudocode for computing the matrix-vector product of A with a vector x. That is, given vectors a, b, and c that define A as in definition (1), and given a vector 2, E R", your algorithm should compute the matrix-vector product y- A. Your pseudocode should have the following form: Input: vectorRn and vectors R", be Rn-1 and E Rn-2 Insert pseudocode here Output: vector R's such that Ai (b) Analyse the complexity of the algorithm from part (a). That is, determine how many flops are required to compute the product y = Ax with your algorithm. In terms of "Big-Oh" notation, what is the asymptotic behaviour of your algorithm as n increases? (c) Implement your pseudo-code in as a function called tridag matvec.py. Also, write a script called compare.py to generate a tridiagonal test matrix and a test vector for a n = 10k, k 2,... ,7, compute the product and measure the time your code takes to complete. Produce a plot of the time taken versus n on a logarithmic scale, along with your prediction (d) Repeat the test, but now using the built-in matrix-vector product (scipy.dot/scipy.matmul) and the matrix A defined as an n n matrix with mostly zeros. Plot the time taken in the same plot as for (c). Which algorithm is faster? Is the difference as great as you expected? The banded, upper triangular matrix A ERXn can be written as 1 01 C1 Clo bC3 n-2 On-2 Cn-2 an-1 bn-1 CU rl where a = (al , a2, . . . , an-2, an-i,an) E R", 1,02- ,0n-2, 0n-1 The entries of a, b, and c are all assumed to be nonzero (a) Write a pseudocode for computing the matrix-vector product of A with a vector x. That is, given vectors a, b, and c that define A as in definition (1), and given a vector 2, E R", your algorithm should compute the matrix-vector product y- A. Your pseudocode should have the following form: Input: vectorRn and vectors R", be Rn-1 and E Rn-2 Insert pseudocode here Output: vector R's such that Ai (b) Analyse the complexity of the algorithm from part (a). That is, determine how many flops are required to compute the product y = Ax with your algorithm. In terms of "Big-Oh" notation, what is the asymptotic behaviour of your algorithm as n increases? (c) Implement your pseudo-code in as a function called tridag matvec.py. Also, write a script called compare.py to generate a tridiagonal test matrix and a test vector for a n = 10k, k 2,... ,7, compute the product and measure the time your code takes to complete. Produce a plot of the time taken versus n on a logarithmic scale, along with your prediction (d) Repeat the test, but now using the built-in matrix-vector product (scipy.dot/scipy.matmul) and the matrix A defined as an n n matrix with mostly zeros. Plot the time taken in the same plot as for (c). Which algorithm is faster? Is the difference as great as you expected
Step 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