Error when calling function, "Invalid expression..."
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!