Advertisement
Guest User

Untitled

a guest
May 16th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.73 KB | None | 0 0
  1. function L = limiteRaizes(n, c)
  2.     L = zeros(4);
  3.     // n -> grau do polinomio
  4.     // c -> coeficientes do polinomio
  5.     if( c(1) == 0 )
  6.         print("coeficiente c(1) nulo");
  7.         break;
  8.     end
  9.     t = n+1;
  10.     c(t+1) = 0;
  11.     while(1) // REVISAR
  12.         if(c(t) ~= 0) break; end
  13.         t = t - 1;
  14.     end
  15.    
  16.     // calculo dos quatro limites reais
  17.     for( i = 1:4 )
  18.         if( i == 2 | i == 4)
  19.             for(j = 1:t/2)
  20.                 Aux = c(j);
  21.                 c(j) = c(t-j+1);
  22.                 c(t-j+1) = Aux;
  23.             end
  24.         else
  25.             if( i == 3 )
  26.                  for( j = 1:t/2)
  27.                      Aux = c(j);
  28.                      c(j) = c(t-j+1);
  29.                      c(t-j+1) = Aux;
  30.                  end                
  31.                  for(j = t-1:-2:1) c(j) = -1*c(j); end
  32.             end
  33.         end
  34.        
  35.         // se c(1) negativo
  36.         if(c(1) < 0)
  37.             for(j = 1:t) c(j) = -1 * c(j); end
  38.         end
  39.         k = 2;
  40.         while(1)
  41.             if(c(k) < 0 | k > t) break; end
  42.             k = k + 1;
  43.         end // calculo de B, o maior coeficiente negativo em modulo
  44.        
  45.         if( k <= t )
  46.             B = 0;
  47.             for( j = 2:t )
  48.                 if( c(j) < 0 & abs(c(j)) > B) B = abs(c(j)); end
  49.             end
  50.             // limite das raizes positivas de P(x) = 0 e das equa                   çáes auxiliares
  51.             L(i) = 1 + (B/c(1)).^(1/(k-1));
  52.          else
  53.              L(i) = 10.^100;
  54.          end
  55.      end
  56.      Aux = L(1);
  57.      L(1) = 1/L(2);
  58.      L(2) = Aux;
  59.      L(3) = -1*(L(3));
  60.      L(4) = -1/(L(4));
  61. endfunction
  62.  
  63. // parametros de entrada
  64. n = 4;
  65. c = [1 2 -13 -14 24];
  66. // resultados
  67. disp(limiteRaizes(n,c));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement