Provence

BUG_scilab

Feb 21st, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 2.85 KB | None | 0 0
  1. //MAHJOUB BONNAIRE
  2. //provence
  3. //L3 Meca
  4.  
  5. //Programe d'interpolation de lagrange
  6.  
  7. //Debut du programme
  8.  
  9. //nettoyage du cache
  10.  
  11. clear
  12. clf(1)
  13.  
  14. //RECUPERATION DONNEES
  15.  
  16. //Dir(school)
  17.  
  18. //A=fscanfMat('\\ad.u-ga.fr\home_etu\m\mahjoubp\Bureau\Scillab\TP3\data.sce')
  19.  
  20. //Dir(home)
  21.  
  22. A=fscanfMat('/home/provence/Bureau/scilab-6.0.1.bin.linux-x86_64/scilab-6.0.1/projet/apdata/data_lagrange_2.sce')
  23.  
  24. //Input #1
  25.  
  26. N=size(A)
  27. n=N(1,1)
  28. p=input("Quel pas voulez vous ? (x)")
  29.  
  30. //initialisation de xinc
  31.  
  32. xinc=0
  33. xd=A(1,1)
  34. xu=A(n,1)
  35. nx=(xu-xd)/p
  36.  
  37. //declaration des tab
  38.  
  39. x=zeros(n,1)
  40. y=zeros(n,1)
  41. X=zeros(n+nx,1)
  42. Y=zeros(n+nx,1)
  43.  
  44. //Input #2
  45.  
  46. k=1
  47. while k<n+1
  48.     x(k)=A(k,1)
  49.     y(k)=A(k,2)
  50.     k=k+1
  51. end
  52.  
  53. //declaration de fonction
  54.  
  55. function [p]=Pn(n,x,y,xinc)
  56.     Lk=1
  57.     k=1
  58.     i=1
  59.     pp=0
  60.     while i<n+1
  61.         while k<n+1
  62.             if k<>i  then
  63.                 Lk=Lk*(xinc-x(k))/(x(i)-x(k))
  64.             end
  65.             k=k+1
  66.         end
  67.         k=1
  68.         pp=pp+y(i)*Lk
  69.         Lk=1
  70.         i=i+1
  71.     end
  72.     p=pp
  73. endfunction
  74.  
  75.  
  76. //utilisation de la fonction Pn
  77.  
  78. //res=Pn(n,x,y,xinc)
  79. //disp(res)
  80.  
  81.  
  82. //Remplissage de X et Y
  83.  
  84. function [X,Y,btf]=Coord(n,x,y,xinc,res)
  85. k=1
  86. kk=1
  87. tf=0
  88. btf=1
  89. while k<n+1
  90.     if x(k,1)>xinc & tf==0
  91.         tf=1
  92.         btf=0
  93.         // ATTENTION : BUG !
  94.        
  95.         /*Le programme rentre dans cette condition alors que xinc==x(k)
  96.         disp(x(k),"xxxxxxxxxxxx")
  97.         disp(xinc,"xiiiiiiiiiii")
  98.         */
  99.         X(kk+1)=x(k)
  100.         X(kk)=xinc
  101.         Y(kk+1)=y(k)
  102.         Y(kk)=res
  103.         kk=kk+1
  104.     end
  105.     if x(k,1)==xinc
  106.         // ATTENTION : BUG !
  107.        
  108.         //Le programme ne rentre pas dans cette condition alors que xinc==x(k)
  109.         disp(x(k),"xxxxxxxxxxxx")
  110.         disp(xinc,"xiiiiiiiiiii")
  111.        
  112.         tf=1
  113.         X(kk)=x(k)
  114.         Y(kk)=y(k)
  115.     end
  116.     if x(k,1)>xinc & tf==1
  117.         X(kk)=x(k)
  118.         Y(kk)=y(k)
  119.     end
  120.     if x(k,1)<xinc then
  121.         X(kk)=x(k)
  122.         Y(kk)=y(k)
  123.     end
  124.     k=k+1
  125.     kk=kk+1
  126. end
  127.  
  128. endfunction
  129.  
  130. //utilisation de la focntion Coord
  131.  
  132. //[X,Y]=Coord(n,x,y,xinc,res)
  133.  
  134. //disp(X)
  135. //disp(Y)
  136.  
  137. //Fonction d'incrementation de pas
  138.  
  139. function [XY]=incp(n,x,y,p,nx,xd)
  140.    
  141.     k=1
  142.     xinc=xd+p
  143.     while k<nx
  144.         res=Pn(n,x,y,xinc)
  145.         [X,Y,btf]=Coord(n,x,y,xinc,res)
  146.         x=X
  147.         y=Y
  148.         if btf==0 then
  149.             n=n+1
  150.         end
  151.         xinc=xinc+p
  152.         k=k+1        
  153.     end
  154.     XY=[X,Y]
  155.    
  156. endfunction
  157.  
  158. //utilisation de la fonction incp
  159.  
  160. [XY]=incp(n,x,y,p,nx,xd)
  161.  
  162. disp(XY)
  163.  
  164. //fonction de tracage
  165.  
  166. function graph(XY)
  167.     xset("window",1)
  168.     S=size(XY)
  169.     s=S(1,1)
  170.     k=1
  171.     while k<s
  172.         plot([XY(k,1),XY(k+1,1)],[XY(k,2),XY(k+1,2)])
  173.         k=k+1
  174.     end
  175. endfunction
  176.  
  177. //utilisation de la fonction de tracage
  178.  
  179. graph(XY)
Add Comment
Please, Sign In to add comment