필터 지우기
필터 지우기

I want to ask what wrong with my codes . please help me out

조회 수: 1 (최근 30일)
JALALUDIN ARIS
JALALUDIN ARIS 2021년 6월 24일
댓글: JALALUDIN ARIS 2021년 6월 24일
% Power Method Algorithm
n=input('Enter dimension of the matrix, n: ');
A = zeros(n,n);
x = zeros(1,n);
y = zeros(1,n);
tol = input('Enter the tolerance, tol: ');
m = input('Enter maximum number of iteration, m: ');
A=[0.000251 0.000163 ; 0.000251 0.0003261];
x=[-2.1; 0.9];
k = 1; 1p = 1;
amax = abs (x(1));
for i = 2 : n
if abs(x(i)) > amaz
amax = abs(x(i));
1p = i;
end
end
for i = 1 : n
x(i) = x(i)/max;
end
fprintf('\n\n Ite. Eigenvalue..........Eigenvectores..........\n');
while k <= m
for i = 1 : n
y(i) = 0;
for j = 1 : n
y(i) = y(i) + A(i,j) * x(j);
end
end
ymu = y(1x);
1p = 1;
amax = abs(y(1));
for i = 2 : n
if abs(y(i)) > amax
amax = abs(y(i));
1p = i;
end
end
if amax <= 0
fprintf('0 eigenvalue - select another ');
fprint('initial vector and begin again\n');
else
err = 0;
for i = 1 : n
t = y(i)/y(1p);
if abs(x(i)-t) > err
err = abs(x(i)-t);
end
x(i) = t;
end
fprintf('%4d %11.8f' , k, ymu);
for i = 1 : n
fprintf(' %11.8f', x(i));
end
fprintf('\n');
if err <= tol
fprintf('\n\nThe eigenvalue after %d iterations is: %11.8f \n',k, ymu);
fprintf('The corresponding eigenvector is: \n');
for i = 1 ; n
fprintf(' %11.8f\n', x(i));
end
fprintf ('\n');
break
end
k= k+1;
end
end
if k > m
fprintf ('Method did not coverge within %d iteration\n', m);
end
the error :
File: power_method.m Line: 15 Column: 9
Invalid expression. Check for missing multiplication operator, missing or unbalanced
delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

답변 (2개)

KSSV
KSSV 2021년 6월 24일
You should not name a variable starting with a number. Variable name should start with a character.
Replace the variable
1p = 1 ;
with
p1 = 1 ;

Walter Roberson
Walter Roberson 2021년 6월 24일
1p is not a valid variable name in MATLAB. There are not many computer languages in which it would be considered a valid variable name without some special marking (for example in Maple it could be a valid variable name if you marked it as `1p`). The last computer language that I saw that permitted such variable names without special distinction was Algol 68.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by