Error when calling function, "Invalid expression..."

조회 수: 5 (최근 30일)
Jordan Chancellor
Jordan Chancellor 2019년 2월 9일
댓글: Jordan Chancellor 2019년 2월 9일
I am trying to write a code to perform Gauss Elimination on any [nxn] sized matrix, but am having trouble with my back substitution after getting my matrix into row echelon form. I keep getting the error, "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters." on line 35 (the line with the symsum function). I am not familiar with Matlab at all, and so also do not know how to get the output of my function. Any help would be appreciated!
function X = GaussElim(A,b)
[m,n] = size(A)
aug = [A,b]
for k = 1:n+1
m = k
for j = k+1:n
if abs(aug(m,k)) < abs(aug(j,k))
m = j
end
if aug(m,k) == 0
fprintf('No unique solution exists.')
break
else
aug([k m],:) = aug([m k],:)
if aug(n,n) == 0
fprintf('No unique solution exists.')
break
else
for j = k+1:n
M(j,k) = aug(j,k)/aug(k,k)
for p = k:n+1
aug(j,p) = aug(j,p)-(M(j,k)*aug(k,p))
end
end
end
end
end
end
x(n) = (A(n,n+1))/(A(n,n))
for i = n-1:1
x(i) = (1/A(i,i))(A(i,n+1) - symsum((A(i,j)*x(j)), j, [i+1, n]))
end
x(j) = x
end
A = [3.4, -6.12, -2.72; -0.5, 1.80, 0.80; 2, -4.86, 2.16;]
b = [0;2;1]
x = GaussElim(A,b)
  댓글 수: 2
madhan ravi
madhan ravi 2019년 2월 9일
(1/A(i,i))
% ^-—- operator missing !
Jordan Chancellor
Jordan Chancellor 2019년 2월 9일
Thank you!! I fixed it.

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

답변 (0개)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by