Advertisement
SilLAwNeD

Scilab, place function

Oct 14th, 2018
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.71 KB | None | 0 0
  1. function [i] = place(T, t)
  2.    
  3. // Fonction qui prend en paramètre un vecteur colonne
  4. // et un nombre réel et renvois la position de ce nombre
  5. // Le vecteur peut être trié ou non.
  6.  
  7.     i = 0;
  8.    
  9.     // Pour trier le vecteur de façon croissante
  10.     T = gsort(T, 'g', 'i');
  11.    
  12.     // Algo de dichtomie proposée dans l'énoncé
  13.     imin = 1;
  14.     imax = size(T, 1);
  15.     mil = 0;
  16.    
  17.     if ((t < T(1)) | (t > T(imax))) then
  18.         error("t n`est pas dans l`intervalle");
  19.     end
  20.    
  21.     while (imax - imin) > 1
  22.         mil = int((imax + imin)/2);
  23.         if t >= T(mil)
  24.             imin = mil;
  25.         else
  26.             imax = mil;
  27.         end;
  28.     end;
  29.    
  30.     i = imin;
  31.    
  32. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement