Error when computing Gauss Elimination on matrix, "Undefined function 'symsum' for input arguments of type 'double'".

조회 수: 4 (최근 30일)
Writing a function for Gauss Elimination of any sized matrix, and am trying to use a pseudocode to help me write it. In the pseudocode, a summation is used, and so when I try to include the sum in my code (line 36), I get the error "Undefined function 'symsum' for input arguments of type 'double'."
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
for n = 1:n
x(n) = (A(n,n+1))/(A(n,n))
for i = 1:n
x(i) = (1/A(i,i))*(A(i,n+1) - symsum((A(i,j)*x(j)), j, [i+1, n]))
end
end
x(j) = x
end
A = [1 2 3; 2 3 4; 3 4 1;]
b = [4;1;2]
x = GaussElim(A,b)

답변 (1개)

Walter Roberson
Walter Roberson 2019년 2월 9일
You have to pass symsum a symbolic expression , followed by a symbolic variable name, followed by a lower bound, followed an upper bound . symsum takes the expression and tries to calculate from it the asymptomatic general formula for sum based on that variable . Then symsum substitutes the upper bound and the lower bound and subtracts to calculate the sum over the bounds.
Symsum is for calculating formula . Like feeding in the coefficients from a taylor series and hoping to get back the form of the function .
There is no general formula possible for indexing a matrix. It is never possible to use a symbolic variable to index a matrix in MATLAB.
You need to give up on using symsum for this . Any time you want to add a definite series of symbolic terms, calculate all of the terms into a vector and sum() the vector .
sum(A(i,i+1:n).*x(i+1:n))

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by