Page 243 - MATLAB an introduction with applications
P. 243
228 ——— MATLAB: An Introduction with Applications
>> L * U
ans =
4 –1 0 0
–1 4 –1 0
0 –1 4 –1
0 0 –1 4
>> A = [4 –1 0 0;–1 4 –1 0;0 –1 4 –1;0 0 –1 4];
>> d = L\b
d =
1.0000
0.2500
0.0667
0.0179
>> x = U\d
x =
0.2679
0.0718
0.0191
0.0048
MATLAB Solution [Using built-in function]:
>> A = [4 –1 0 0;–1 4 –1 0;0 –1 4 –1;0 0 –1 4];
>> B = [1;0;0;0];
>> x = A\B
x =
0.2679
0.0718
0.0191
0.0048
>> x = inv(A) B
*
x =
0.2679
0.0718
0.0191
0.0048
function A = householder(A)
% Householder reduction of A to tridiagonal form A = [c\d\c]
%Extract c and d by d = diag(A), c = diag(A,1)
%Usage: A = householder(A)