that uie buttu ercise 2.6.5 Use MATLAB to explore the extent of cancellation whe
ID: 3209774 • Letter: T
Question
that uie buttu ercise 2.6.5 Use MATLAB to explore the extent of cancellation when Gaussian elimination is performed on larger Hilbert matrices. (a) In MATLAB, type A = hilb (7) to get H7. To get the LU decomposition with partial pivoting, type [L,U] = lu (A) . Notice that the matrix L is not itself unit lower triangular, but it can be made unit lower triangular by permuting the rows. This is because MATLAB's lu command incorporates the row interchanges in the L matrix. Our real object of interest is the matrix U, which is the triangular matrix resulting from Gaussian elimination. Notice that the further down in U you go, the smaller the numbers become. The ones at the bottom appear to be zero. To get a more accurate picture, type format long and redisplay U. (b) Generate H12 and its LU decomposition. Observe the U matrix using format long. It suffices to print out the last column of U, as this tells the story.Explanation / Answer
clc;
clear all;
close all;
format short
%%%%% a)
A=hilb(7);
[l1 u1]=lu(A);
fprintf(' U matrix : ');
disp(u1);
format long
fprintf('after using long format U matrix : ');
disp(u1);
%%%% b)
A=hilb(12);
[l2 u2]=lu(A);
fprintf('last column of U matrix : ');
disp(u2(:,end));
OUTPUT:
U matrix :
1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429
0 0.0833 0.0889 0.0833 0.0762 0.0694 0.0635
0 0 0.0063 0.0107 0.0134 0.0149 0.0157
0 0 0 0.0010 0.0022 0.0031 0.0038
0 0 0 0 -0.0000 -0.0001 -0.0001
0 0 0 0 0 0.0000 0.0000
0 0 0 0 0 0 -0.0000
after using long format U matrix :
Columns 1 through 6
1.000000000000000 0.500000000000000 0.333333333333333 0.250000000000000 0.200000000000000 0.166666666666667
0 0.083333333333333 0.088888888888889 0.083333333333333 0.076190476190476 0.069444444444444
0 0 0.006349206349206 0.010714285714286 0.013358070500928 0.014880952380952
0 0 0 0.001041666666667 0.002164502164502 0.003100198412698
0 0 0 0 -0.000032982890126 -0.000085034013605
0 0 0 0 0 0.000000885770975
0 0 0 0 0 0
Column 7
0.142857142857143
0.063492063492063
0.015698587127159
0.003815628815629
-0.000142714428429
0.000002675895533
-0.000000030032498
last column of U matrix :
0.083333333333333
0.043650793650794
0.016751949317739
0.005964430306536
0.001003095780172
0.000121017426510
-0.000004610187676
-0.000000362689590
-0.000000009030553
-0.000000000150119
0.000000000001834
-0.000000000000005
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.