Not enough input arguments.

Hi y'all, I'm trying to create a function that can determine the rank, pivots, and free variables of a matrix without just using rank(A). I thought my code looked good but whenever I try to run it it tells me I need more input arguments. I'm pretty new to Matlab and cannot figure out what I is wrong with it. My code is here:
function csolve(A)
[num_rows, num_cols] = size(A);
free_vars = 1:1:num_cols;
pivots = [];
R = rref(A);
for i = 1:1:num_rows
for j = 1:1:num_cols
if R(i,j) == 1
pivots = [pivots, j];
break
end
rank = length(pivots);
free_vars = free_vars(pivots);
end
end
fprintf("The rank of the coefficient matrix is " + rank + ".");
fprintf("Pivot variables: " + pivots);
fprintf("Free variables: " + free_vars);
Like I said, I'm new so it's very possible that this code will not work correctly anyways, if you can find what input I need to add, that would be greatly appreciated!

1 件のコメント

Walter Roberson
Walter Roberson 2020 年 3 月 1 日
How are you invoking this code?

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

回答 (1 件)

Sai Sri Pathuri
Sai Sri Pathuri 2020 年 3 月 4 日

0 投票

I assume you called the function as below or hit the Run button, which results in the error 'Not enough input arguments'.
csolve
The function expects a matrix as an input. Since you are not passing any input, the error is being thrown. Define matrix A for which the rank, pivots, and free variables are to be determined and call the function in command window as
csolve(A)

カテゴリ

質問済み:

2020 年 3 月 1 日

回答済み:

2020 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by