How to fix the error[Not enough input arguements]

Hi I'm very new to MATLAB and I met this error:
>> TDMAsolver
Not enough input arguments.
Error in TDMAsolver (line 3)
n = length(d); % n is the number of rows
This code is given by my teacher so it should work, but no matter how many times I try, I still can't run the code. Could anybody help me on this? THX
function x = TDMAsolver(a,b,c,d)
%a, b, c are the column vectors for the compressed tridiagonal matrix, d is the right vector
n = length(d); % n is the number of rows
% Modify the first-row coefficients
c(1) = c(1)/b(1); % Division by zero risk. d(1) = d(1)/b(1);
for i = 2 : n - 1
temp = b(i) - a(i) * c(i - 1);
c(i) = c(i)/temp;
d(i) = (d(i) - a(i) * d(i - 1))/temp;
end
d(n) = (d(n) - a(n) * d(n - 1))/(b(n) - a(n) * c(n - 1)); % Now back substitute.
x(n) = d(n);
for i = n - 1 : -1 : 1
x(i) = d(i) - c(i) * x(i + 1);
end
end

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日

0 投票

You need to pass the values of inputs a, b, c, d. For example
a = rand(10,1);
b = rand(10,1);
c = rand(10,1);
d = rand(10,1);
TDMAsolver(a,b,c,d)

2 件のコメント

Hanwen Zhang
Hanwen Zhang 2020 年 11 月 2 日
thanks for your answer! I just realized that Matlab is very different from Pyhton. I thought after defining this function and run, I would get no error like Pyhton. However in Matlab this is not the case.
Ameer Hamza
Ameer Hamza 2020 年 11 月 2 日
I am glad to be of help!
In MATLAB, the functions have their own workspace and cannot automatically access variables from other workspaces unless you define them as global.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by