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

4 ビュー (過去 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 Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by