Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete c and d. Thanks The banded, upper triangular matrix A ERnXxn can be written as a2 b2 c2 3 an-2 n-2 Cn-2 where

image text in transcribed

Please complete c and d. Thanks

The banded, upper triangular matrix A ERnXxn can be written as a2 b2 c2 3 an-2 n-2 Cn-2 where (ai ,a2, . . . , an-2, an-1, an) e Rn b- (bi, b2,..., bn-2, bn-1) ER" c= (ci, c2 , . . . , cn-2) Rn The entries of a, b, and are all assumed to be nonzero. (a) Write a pseudocode for computing the matrix-vector product of A with a vector x. That is, R", your given vectors a, b, and that define A as in definition (1), and given a vector z algorithm should compute the matrix-vector product y- Az. Your pseudocode should have the following form: Input: vector re Rn and vectors R", b Rn-1 and Rn-2. Insert pseudocode here Output: vector ye Rn such that y-Ar (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- 10*, 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 X 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 ERnXxn can be written as a2 b2 c2 3 an-2 n-2 Cn-2 where (ai ,a2, . . . , an-2, an-1, an) e Rn b- (bi, b2,..., bn-2, bn-1) ER" c= (ci, c2 , . . . , cn-2) Rn The entries of a, b, and are all assumed to be nonzero. (a) Write a pseudocode for computing the matrix-vector product of A with a vector x. That is, R", your given vectors a, b, and that define A as in definition (1), and given a vector z algorithm should compute the matrix-vector product y- Az. Your pseudocode should have the following form: Input: vector re Rn and vectors R", b Rn-1 and Rn-2. Insert pseudocode here Output: vector ye Rn such that y-Ar (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- 10*, 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 X 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago