필터 지우기
필터 지우기

Line 37: Parse error at A: usage might be invalid MATLAB syntax.

조회 수: 3 (최근 30일)
Abul Yasa Hasan
Abul Yasa Hasan 2024년 3월 16일
댓글: Abul Yasa Hasan 2024년 3월 16일
Ques.) Use Householder's method to place the following matrices in tridiagonal form.
I had a basic code provided by the tutor which I adapted to the problem above. However, when I run the I get the error in Line 37(the second last line) - Parse error at A: usage might be invalid MATLAB syntax.
% Test with the given matrix
A = [4.75 2.25 -0.25; 2.25 4.75 1.25; -0.25 1.25 4.75];
hh_tridiag(A);
alpha = -2.2638, r = 2.2604, w = 0 0.99847 -0.0553 P^(1) = 1.0000 0 0 0 -0.9939 0.1104 0 0.1104 0.9939 A^(2) = 4.7500 -2.2638 -0.0000 -2.2638 4.4756 -1.2195 -0.0000 -1.2195 5.0244
function hh_tridiag(A)
n = size(A, 1);
for k = 1:(n-2)
% Calculate t and alpha
t = sqrt(sum(A((k+1):end, k).^2));
if A(k+1, k) ~= 0
alpha = -sign(A(k+1, k)) * t;
else
alpha = -t;
end
% Calculate r and w
r = sqrt((alpha^2 - A(k+1, k) * alpha) / 2);
w = zeros(n, 1);
w(k+1) = (A(k+1, k) - alpha) / (2 * r);
for j = (k+2):n
w(j) = A(j, k) / (2 * r);
end
disp(['alpha = ', num2str(alpha), ', r = ', num2str(r), ', w = ', num2str(w')]);
% Calculate Householder matrix P
P = eye(n) - 2 * (w * w');
disp(['P^(', num2str(k), ') =']);
disp(P);
% Update A
A = P * A * P';
disp(['A^(', num2str(k+1), ') =']);
disp(A);
end
end
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2024년 3월 16일
The code runs without any error (see the edit above).
Make sure if you are running this as a script, the function is placed at the bottom of the script.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by