I need this program to only output one time. Right now it is outputting for every individual element in the s matrix.

2 vues (au cours des 30 derniers jours)
When I run this program it runs through every single element and has an output for every number in the matrix. How can I make it give one output hwne its run?
function [] = Prgrm1(A,b)
s = rref([A,b]);
s1 = rref(A);
[m,n] = size(s);
s2 = eye(size(s1));
for w=1:m
for q=1:n
if s(:,1:end-1)==s2
disp('Unique Solution');
x=A\b;
disp(x);
elseif (s(w)~=0 || (s(w)==0 && s(q(:,end))==0))
disp('Infinitely Many Solutions');
t=s1(q(:,1:end))>=0
disp('Number of solutions:');
disp(t);
else
disp('No Solution');
end
end
end
end
What I'm getting looks like:
>> Prgrm1([1 0 1; 0 1 1], [1; 1])
Infinitely Many Solutions
t =
logical
1
Number of solutions:
1
Infinitely Many Solutions
t =
logical
0
Number of solutions:
0
Infinitely Many Solutions
t =
logical
0
Number of solutions:
0
Infinitely Many Solutions
t =
logical
1
Number of solutions:
1
No Solution
Infinitely Many Solutions
t =
logical
0
Number of solutions:
0
Infinitely Many Solutions
t =
logical
0
Number of solutions:
0
No Solution
>> Prgrm1([1 0 ; 0 1 ], [1; 1])
Unique Solution
1
1
Unique Solution
1
1
Unique Solution
1
1
Unique Solution
1
1
Unique Solution
1
1
Unique Solution
1
1

Réponses (1)

Payam Morsali
Payam Morsali le 18 Oct 2020
try using ";" after t=s1(q(:,1:end))>=0

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by