# Error in while loop

13 ビュー (過去 30 日間)
Mughees Asif 2019 年 3 月 19 日
コメント済み: Torsten 2019 年 3 月 19 日
function IsStable(polynomial)
if AllNonZero(polynomial) == false
H=[]
elseif AllSameSign(polynomial) == false
H=[]
else
HurwitzMatrix(polynomial);
pm = length(polynomial);
while 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 run this code but get this error,
Undefined function or variable 'minor'.
Error in IsStable (line 12)
if minor(i)>0
Any suggestions? Thank you.

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Torsten 2019 年 3 月 19 日
Do you want a different value for B for each minor, i.e. B(i) instead of B ?
Then use
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));
if minor(i) > 0
B(i) = 1
else
B(i) = 0
end
end
end

#### 4 件のコメント

Torsten 2019 年 3 月 19 日
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
B = Inf;
if minor > 0
B = 1;
else if minor < 0
B = 0;
end
end
To avoid the error, define the array/matrix "polynomial" you pass to "IsStable" properly.
Mughees Asif 2019 年 3 月 19 日
This is not for a specific polynomial, it should work forany arbitrary polynomial,
So for example, this is how I call the function in the command window,
>>IsStable([1.0000 1.2000 0.8562 0.3360 0.0321 0.0539])
The input vector can be any arbitrary vector basically. Thank you for the replies.
Torsten 2019 年 3 月 19 日
And what do you expect polynomial(1:i,1:i) to be for this polynomial ? As defined, your polynomial is a vector, not a matrix.

サインイン to comment.

### その他の回答 (0 件)

サインイン してこの質問に回答します。