Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using MATLAB 2. (20 pts) Consider matrix A that has -2 for each diagonal entry,

ID: 664890 • Letter: U

Question

Using MATLAB

2. (20 pts) Consider matrix A that has -2 for each diagonal entry, 1's on each of the first upper and lower diagonals, and the rest of the matrix is all O's. Such a matrix is encountered in numerically solving differential equations. It is considered to be sparse because is consists of mostly O's Let b be a vector of all nes. For n-10, 100, 1000 a) Create the matrix A by first creating a matrix of all 0's, then putting in the -2's on the main diagonal and 1's on the first upper and lower diagonals. Solve Ax = b using backslash, and time it using 'tic, and toc. Hint: Using the ‘diag, command can help here. b) Repeat the process, but using the sparse matrix format for A. You can do this inefficiently using the 'sparse' command to turn your matrices from part a) into sparse format. A much better way to do this is to create the matrix using the 'spdiags' command. The syntax to do this can be found in the help ), 2000, 4000, 8000: timing difference between solving sparse and full matrices using backslash? Hovw much?

Explanation / Answer

a) A=[0 0 0; 0 0 0; 0 0 0];
A=[-2 1 -2; 0 -2 0; -2 1 -2];
B=[1 1 1;1 1 1;1 1 1];
X=AB

b) X =spdiags(B,X,A)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote