I am finding error while writting code of tridiagonal matrix as my matlab do not konw what is tridiagonal

1 visualizzazione (ultimi 30 giorni)
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);

Risposte (1)

KSSV
KSSV il 2 Ott 2021
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 Commenti
KSSV
KSSV il 2 Ott 2021
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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by