Page 262 - MATLAB an introduction with applications
P. 262
Numerical Methods ——— 247
Check with MATLAB built-in function:
>> A = [1 1 1;3 3 4;2 1 1];
b = [7;23;10];
>> x = A\b
x =
3.0000
2.0000
2.0000
Example E4.23: Solve the system of equations by Choleski’s factorization method:
12x – 6x – 6x – 1.5x = 1
3
2
4
1
–6x + 4x + 3x + 0.5x = 2
3
4
1
2
–6x + 3x + 6x + 1.5x = 3
2
3
4
1
–1.5x + 0.5x + 1.5x + x = 4
3
2
1
4
Solution:
Here the matrix [A] is symmetric.
Program and the output are given below:
A = [12 –6 –6 –1.5;–6 4 3 0.5;–6 3 6 1.5; –1.5 0.5 1.5 1];
b = [1;2;3;4];
[L,U] = lu(A);
% solution of y
y = L\b;
%final solution x
x = U\y;
fprintf(‘Solution of the equations is\n’);
disp(x)
The solution of the equations is
2.7778
4.2222
–0.5556
6.8889
Check with MATLAB built-in function:
>> A = [12 –6 –6 –1.5; –6 4 3 0.5; –6 3 6 1.5; –1.5 0.5 1.5 1];
b = [1;2;3;4];
>> x = A\b
x =
2.7778
4.2222
–0.5556
6.8889