Calculator Community > TI-BASIC
Routh-Hurwitz Matlab to TI-Nspire
(1/1)
APoloG13:
Hello everyone,
I'm opening this topic for asking for help, because yesterday i found a very precise script for finding the Routh-Hurwitz of a function. Those were good news, bad news: it's a matlab script.
Anyone knows how to convert this script to Basic or LUA (don't know wich will be better)
The link to de matlab script: http://www.mediafire.com/file/0i9cl6ba956abb1/rhc.m
Hope anybody had any kind of info to help me... Thx
Xeda112358:
For reference, the code linked:
Spoiler For "code":
--- Code: ---function [] = rhc( r )
%The Routh-Hurwitz stability criterion is a necessary (and frequently
%sufficient) method to establish the stability of a single-input,
%single-output (SISO), linear time invariant (LTI) control system.
%More generally, given a polynomial, some calculations using only the
%coefficients of that polynomial can lead us to the conclusion that it
%is not stable.
%in this program you must give your system coefficents and the
%Routh-Hurwitz table would be shown
m=length(r);
n=round(m/2);
q=1;
k=0;
for p = 1:length(r)
if rem(p,2)==0
c_even(k)=r(p);
else
c_odd(q)=r(p);
k=k+1;
q=q+1;
end
end
a=zeros(m,n);
if m/2 ~= round(m/2)
c_even(n)=0;
end
a(1,:)=c_odd;
a(2,:)=c_even;
if a(2,1)==0
a(2,1)=0.01;
end
for i=3:m
for j=1:n-1
x=a(i-1,1);
if x==0
x=0.01;
end
a(i,j)=((a(i-1,1)*a(i-2,j+1))-(a(i-2,1)*a(i-1,j+1)))/x;
end
if a(i,:)==0
order=(m-i+1);
c=0;
d=1;
for j=1:n-1
a(i,j)=(order-c)*(a(i-1,d));
d=d+1;
c=c+2;
end
end
if a(i,1)==0
a(i,1)=0.01;
end
end
Right_poles=0;
for i=1:m-1
if sign(a(i,1))*sign(a(i+1,1))==-1
Right_poles=Right_poles+1;
end
end
fprintf('\n Routh-Hurwitz Table:\n')
a
fprintf('\n Number Of Right Poles =%2.0f\n',Right_poles)
fprintf('\n Given Polynomials Coefficents Roots :\n')
ROOTS=roots(r)
end
--- End code ---
I'm not very familiar with matlab, so I hope this works. Here is the first part:
Spoiler For "first part":
--- Code: ---length(r)->m
augment(r,{0})->r
int(.5+r/2)->n
newMatrix(m,n)->a
for k,1,n
r[k*2-1]->a[1,k]
r[k*2]->a[2,k]
EndFor
m->order
For i,3,m
For j,1,n-1
a[i-1,1]->c
limit((x*a[i-2,j+1]-a[i-2,1]*a[i-1,j+1])/x,x,c)->a[i,j]
EndFor
--- End code ---
Here is the next line, which I don't know how to translate:
--- Code: ---if a(i,:)==0
--- End code ---
And the next chunk, translated:
Spoiler For "next part":
--- Code: ---for j,1,n-1
(order-2*j)*a[i-1,j]->a[i,j]
EndFor
order-1->order
EndIf
EndFor
0->Right_poles
for i,1,m-1
If sign(a[i,1])*sign(a[i+1,1])=-1:Then
Right_poles+1->Right_poles
EndIf
EndFor
--- End code ---
And this last bit I don't know how to translate:
Spoiler For "???":
--- Code: ---fprintf('\n Routh-Hurwitz Table:\n')
a
fprintf('\n Number Of Right Poles =%2.0f\n',Right_poles)
fprintf('\n Given Polynomials Coefficents Roots :\n')
ROOTS=roots(r)
end
--- End code ---
APoloG13:
Thanks for the effort Xeda112358 but it didn't work, sorry for wasting your time :-[
I ended doing it very very simple and wasn't usefull because it wasn't in the exam :banghead:
Now i'm looking to the "MadeEasy" ti nspire programs, it's a shame you have to pay that much for a single program and when i tried the free version their scripts are blocked with pass... Thought that TI community should be free. There is some kind of "magic" to open that?
Navigation
[0] Message Index
Go to full version