Debug simple function
- or -
Post a project like this1845
£15/hr(approx. $19/hr)
- Posted:
- Proposals: 3
- Remote
- #2340982
- Awarded
Description
Experience Level: Entry
function IsStable(polynomial)
if AllNonZero(polynomial) == false
H = []
elseif AllSameSign(polynomial) == false
H = []
else
HurwitzMatrix(polynomial);
pm = length(polynomial);
minor = zeros(1,pm);
for i = 1:pm
minor(i) = det(polynomial(1:i,1:i));
end
B = Inf;
if minor > 0
B(i) = 1;
else minor < 0;
B(i) = 0;
end
end
end
I keep getting the error:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in IsStable (line 11)
minor(i) = det(polynomial(1:i,1:i));
I am trying to calculate the stability of a Hurwitz Matrix in MATLAB by checking if the principle minors are more than zero. I have written 3 different .m files that work perfectly except this last one that should take a row vector representing a polynomial, and
returns a value 0 (False) if not all solutions of the polynomial have a real part that is strictly
smaller than zero, and a value 1 (True) otherwise. The function file should first check
the two necessary conditions above and only carry on calculating a Hurwitz matrix
if both conditions are satisfied. It should also return the Hurwitz matrix when it
has been calculated and an empty matrix otherwise. When checking whether all
principal minors are positive, I want to use a while loop and stop the checking when
a negative or zero principal minor is encountered.
if AllNonZero(polynomial) == false
H = []
elseif AllSameSign(polynomial) == false
H = []
else
HurwitzMatrix(polynomial);
pm = length(polynomial);
minor = zeros(1,pm);
for i = 1:pm
minor(i) = det(polynomial(1:i,1:i));
end
B = Inf;
if minor > 0
B(i) = 1;
else minor < 0;
B(i) = 0;
end
end
end
I keep getting the error:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in IsStable (line 11)
minor(i) = det(polynomial(1:i,1:i));
I am trying to calculate the stability of a Hurwitz Matrix in MATLAB by checking if the principle minors are more than zero. I have written 3 different .m files that work perfectly except this last one that should take a row vector representing a polynomial, and
returns a value 0 (False) if not all solutions of the polynomial have a real part that is strictly
smaller than zero, and a value 1 (True) otherwise. The function file should first check
the two necessary conditions above and only carry on calculating a Hurwitz matrix
if both conditions are satisfied. It should also return the Hurwitz matrix when it
has been calculated and an empty matrix otherwise. When checking whether all
principal minors are positive, I want to use a while loop and stop the checking when
a negative or zero principal minor is encountered.
Mughees A.
100% (8)Projects Completed
10
Freelancers worked with
6
Projects awarded
79%
Last project
10 Jan 2022
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies