Author Topic: Routh-Hurwitz Matlab to TI-Nspire  (Read 8804 times)

0 Members and 1 Guest are viewing this topic.

Offline APoloG13

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Routh-Hurwitz Matlab to TI-Nspire
« on: October 24, 2016, 02:22:04 pm »
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

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Routh-Hurwitz Matlab to TI-Nspire
« Reply #1 on: October 24, 2016, 05:59:53 pm »
For reference, the code linked:
Spoiler For "code":
Code: [Select]
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

I'm not very familiar with matlab, so I hope this works. Here is the first part:
Spoiler For "first part":
Code: [Select]
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
Here is the next line, which I don't know how to translate:
Code: [Select]
if a(i,:)==0And the next chunk, translated:
Spoiler For "next part":
Code: [Select]
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
And this last bit I don't know how to translate:
Spoiler For "???":
Code: [Select]
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

Offline APoloG13

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Re: Routh-Hurwitz Matlab to TI-Nspire
« Reply #2 on: December 20, 2016, 02:12:44 pm »
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?