필터 지우기
필터 지우기

How do I write out symbolically what this function does in the case n= 5 for the iteration with j = 3, Using ordinary element wise vector and matrix notation

조회 수: 1 (최근 30일)
function [L, U] = lufacto(A)
% LUFACT LU factorization
% Input:
% A square matrix
% Output:
% (L, U) unit lower triangular and upper triangular such that LU = A
n = length(A);
L = eye(n); % ones on diagonal
% Gaussian elimination
for j = 1:n-1
L(j+1:n, j) = A(j+1:n, j) / A(j, j);
A(j+1:n, j:n) = A(j+1:n, j:n) - L(j+1:n, j) * A(j, j:n);
end
U = triu(A);
end
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2023년 9월 22일
n = length(A);
Using length() for non-vector, non-square arrays can be confusing (for the lack of a better word).
Instead use the more robust option - size, where the output for a 2D array is
[number_of_rows number_of_columns]

댓글을 달려면 로그인하십시오.

답변 (1개)

Pratyush
Pratyush 2023년 9월 22일
Hi Muhideen,
I understand you want to represent the calculation steps for n=5, in the iteration j=3 using Matrix notation.
Symbolically, the calculations for the given iteration can be represented as:
  • L(4, 3) = A(4, 3) / A(3, 3)
  • L(5, 3) = A(5, 3) / A(3, 3)
  • A(4, 3:5) = A(4, 3:5) - L(4, 3) * A(3, 3:5)
  • A(5, 3:5) = A(5, 3:5) - L(5, 3) * A(3, 3:5)
Note: The above notation assumes 1-based indexing.
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2023년 9월 22일
You are trying to access the 4th and the 5th row of a 3x3 matrix, which is not possible, hence the error.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by