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);

回答(1 个)

KSSV
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
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by