Calling multiple .m files into separate function

function [B, H] = IsStable(polynomial)
if polynomial ~= AllNonZero(polynomial(false))
B=0;
H=[];
elseif polynomial ~= AllSameSign(polynomial(false))
B=0;
H=[];
else
H=HurwitzMatrix(polynomial);
pm = length(H);
for i=1:pm
minor(i)=det(polynomial(1:i,1:i));
end
if minor(i)>0
B=1;
else
B=0;
end
end
I am trying to calculate the stability of a Hurwitz Matrix by checking if the principle minors are more than zero. Any sugestions to improve the above code as it is not working when I call three separate .m files e.g. AllNonZero, AllSameSign and HurwitzMatrix? Thank you.

7 commentaires

What are you passing in as the first parameter? If you are not passing in an object or function handle, then polynomial(false) is a logical indexing request to return none of the elements of polynomial so polynomial(false) is likely to be empty.
The aim is to enter a row vector into the function, which, will cross check with the other three .m files before displaying 1 if the principle minors are more than zero and 0 if the principle minors are less than 0. When the row vector is entered into the function, it should check if all the signs are same, if any number is 0 and display the associated Hurwitz matrix. But for this file, I need it to check and display all three results from the files and then check for the principle minors.
function IsStable(polynomial)
if AllNonZero(polynomial) == false
H=[]
elseif AllSameSign(polynomial) == false
H=[]
else
HurwitzMatrix(polynomial);
pm = length(polynomial);
for i=1:pm
minor(i)=det(polynomial(1:i,1:i));
end
if minor(i)>0
B=1
else
B=0
end
end
I tried changing the parameter but i get the error,
Index in position 1 exceeds array bounds (must not exceed 1).
Error in IsStable (line 10)
minor(i)=det(polynomial(1:i,1:i));
You should presize your array before the for loop:
minor = zeros(1,pm);
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));
if minor(i) > 0
B(i) = 1
else
B(i) = 0
end
end
end
I am still getting the same 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));
Adam
Adam le 19 Mar 2019
So, as Walter asked, what are you passing in as the parameter?
If AllNonZero is false then isn't the matrix all 0 or at least a row of 0?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by