MATLAB Cholesky Decomposition: Solving Linear Equations with Examples
This article demonstrates how to solve linear equations using Cholesky decomposition in MATLAB. We'll provide a detailed example and code implementation.
Cholesky Decomposition for Solving Linear Equations
Cholesky decomposition is a powerful technique for solving linear equations of the form Ax = b, where A is a symmetric positive-definite matrix. The method involves factorizing A into the product of a lower triangular matrix (L) and its transpose (L').
MATLAB Code Implementation
% Cholesky Decomposition to solve Ax = b
% Input matrix A and vector b
A = [4 -2 4; -2 2 -3; 4 -3 14];
b = [-7; 3; 5];
% Check if A is symmetric positive-definite
if ~issymmetric(A) || ~isdefinite(A)
error('A is not a symmetric positive-definite matrix');
end
% Calculate Cholesky decomposition (L and L')
n = size(A,1);
L = zeros(n,n);
for j = 1:n
L(j,j) = sqrt(A(j,j) - L(j,:)*L(j,:)');
for i = j+1:n
L(i,j) = (A(i,j) - L(i,:)*L(j,:)') / L(j,j);
end
end
Lt = L';
% Solve the equation system Ax = b
y = L \ b;
x = Lt \ y;
% Display the solution
disp('Solution of the linear equation system:');
disp(x);
Example Usage
Let's use the following example data:
A = [4 -2 4; -2 2 -3; 4 -3 14];
b = [-7; 3; 5];
The output from the MATLAB code will be:
Solution of the linear equation system:
-1.0000
-2.0000
1.0000
Therefore, the solution to the linear equation system is x = [-1; -2; 1].
Conclusion
Cholesky decomposition provides an efficient and reliable way to solve linear equations when the coefficient matrix is symmetric positive-definite. This method is widely used in various fields, including engineering, physics, and finance.
原文地址: https://www.cveoy.top/t/topic/oZKe 著作权归作者所有。请勿转载和采集!