I need this program to only output one time. Right now it is outputting for every individual element in the s matrix.
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!