I am finding error while writting code of tridiagonal matrix as my matlab do not konw what is tridiagonal
조회 수: 1 (최근 30일)
이전 댓글 표시
function x = Tridiagonal(e,f,g,r)
% Tridiagonal: Tridiagonal equation solver banded system
% x = Tridiagonal(e,f,g,r): Tridiagonal system solver.
% input:
% e = subdiagonal vector
% f = diagonal vector
% g = superdiagonal vector
% r = right hand side vector
% output:
% x = solution vector
n=length(f);
% forward elimination
for k = 2:n
factor = e(k)/f(k-1);
f(k) = f(k) - factor*g(k-1);
r(k) = r(k) - factor*r(k-1);
end
% back substitution
x(n) = r(n)/f(n);
for k = n-1:-1:1
x(k) = (r(k)-g(k)*x(k+1))/f(k);
end
getting error as follows:
> Tridiagonal
Not enough input arguments.
Error in Tridiagonal (line 11)
n=length(f);
댓글 수: 0
답변 (1개)
KSSV
2021년 10월 2일
Do not run th function as code i.e. you are running the code with f5 or using the run button. You need to give inputs to the function and then call it.
% Example
e = value ; % define your variable
f = value ; % define your variable
g = value ; % define your variable
r = value ; % define your variable
% call your function
x = Tridiagonal(e,f,g,r) ;
댓글 수: 5
KSSV
2021년 10월 2일
The question you asked here conveys different. When running code, see to it that the function is saved in the same folder where you are running the code. Or add path of this function.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!