I keep getting this : "The following error occurred converting from sym to double: Unable to convert expression into double array."

2 vues (au cours des 30 derniers jours)
This is my code for the Routh criterion , but ,as the title states, i keep getting error in line 13 : b(i) = e(2*i). I tried to fix the code using others users' suggestions but it still doesn't work. Thank you in advance.
function [k] = routhc(pol)
syms x
k = sym('k');
c = coeffs(pol,x);
e = fliplr(c);
l=length(e);
m=mod(l,2);
if m==0
a=rand(1,(l/2));
b=rand(1,(l/2));
for i=1:(l/2)
a(i)=e((2*i)-1);
b(i)=e(2*i);
end
else
e1=[e 0];
a=rand(1,((l+1)/2));
b=[rand(1,((l-1)/2)),0];
for i=1:((l+1)/2)
a(i)=e1((2*i)-1);
b(i)=e1(2*i);
end
end
%%now we generate the remaining rows of routh matrix
l1=length(a);
c=zeros(l,l1);
c(1,:)=a;
c(2,:)=b;
for m=3:l
for n=1:l1-1
c(m,n)=-(1/c(m-1,1))*det([c((m-2),1) c((m-2),(n+1));c((m-1),1) c((m-1),(n+1))]);
end
end
disp('the routh matrix:');
disp(c);
%%now we check the stablity of system
%syms k
kvalue = solve(c(:,1)>0,k,'ReturnConditions',true);
k = kvalue.conditions
end

Réponses (1)

Harsha Priya Daggubati
Harsha Priya Daggubati le 12 Mai 2020
Hi,
I tried executing the above code using the following polynomial '16*x^2 + 19*x + 11'. Your code executed with no errors, giving the following Routh matrix as a result.
>> routhc(16*x^2 + 19*x + 11)
the routh matrix:
16 11
19 0
11 0
k =
symtrue
ans =
symtrue
Could you provide me with the polynomial you are working with, so I can reproduce the same.

Catégories

En savoir plus sur Stability Analysis 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