Advertisement
Provence

BUG_scilab #2

Feb 24th, 2019
2,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 3.61 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 en x? (ne doit pas être plus petit que +0.00001)")
  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. //Fonsction de decallage
  82.  
  83. function [XX,YY,btf]=suppr2d(X,Y,n,p)
  84.     k=1
  85.     x=0
  86.     kx=0
  87.     while (k<n-2)
  88.         xx=X(k)
  89.         if (x==X(k)) & (k>1) then //ne rentre jamais dans cette boucle a cause du pb
  90.             disp(X(k))
  91.             disp(x,"xxx")
  92.             kk=k
  93.             btf=1
  94.             while kk<n-2
  95.                 X(kk+1)=X(kk+2)
  96.                 Y(kk+1)=Y(kk+2)
  97.                 kk=kk+1
  98.             end
  99.             kk=1
  100.         end
  101.         if (k==1) then
  102.             kx=1
  103.         end
  104.         x=X(k)
  105.         k=k+1
  106.        
  107.     end
  108.     XX=X
  109.     YY=Y
  110.    
  111. endfunction
  112.  
  113. //Remplissage de X et Y
  114.  
  115. function [X,Y,btf]=Coord(n,x,y,xinc,res,p)
  116. k=1
  117. kk=1
  118. tf=0
  119. btf=0
  120. while k<n+1
  121.     if (x(k,1)>xinc) & (tf==0)
  122.         tf=1
  123.         // ATTENTION : BUG !
  124.        
  125.         //Le programme rentre dans cette condition alors que xinc==x(k)
  126.         //disp(x(k),"xxxxxxxxxxxx")
  127.         //disp(xinc,"xiiiiiiiiiii")
  128.        
  129.         X(kk+1)=x(k)
  130.         X(kk)=xinc
  131.         Y(kk+1)=y(k)
  132.         Y(kk)=res
  133.         kk=kk+1
  134.     end
  135.     //disp(x(k,1),"==xxxxxxxxxx")
  136.     //disp(xinc,"==xiiiiiiiii")
  137.     /*if (x(k,1)>=xinc) & (x(k)<=xinc+0.000001)
  138.         // ATTENTION : BUG !
  139.        
  140.         //Le programme ne rentre pas dans cette condition alors que xinc==x(k)
  141.         disp(x(k),"=xxxxxxxxxxxx")
  142.         disp(xinc,"=xiiiiiiiiiii")
  143.        
  144.         tf=1
  145.         X(kk)=x(k)
  146.         Y(kk)=y(k)
  147.     end*/
  148.     if (x(k,1)>xinc) & (tf==1)
  149.         X(kk)=x(k)
  150.         Y(kk)=y(k)
  151.     end
  152.     if x(k,1)<xinc then
  153.         X(kk)=x(k)
  154.         Y(kk)=y(k)
  155.     end
  156.     k=k+1
  157.     kk=kk+1
  158. end
  159.  
  160. [X,Y,btf]=suppr2d(X,Y,n,p)
  161.  
  162. endfunction
  163.  
  164. //utilisation de la focntion Coord
  165.  
  166. //[X,Y]=Coord(n,x,y,xinc,res)
  167.  
  168. //disp(X)
  169. //disp(Y)
  170.  
  171. //Fonction d'incrementation de pas
  172.  
  173. function [XY]=incp(n,x,y,p,nx,xd)
  174.    
  175.     k=1
  176.     xinc=xd+p
  177.     while k<nx
  178.         res=Pn(n,x,y,xinc)
  179.         [X,Y,btf]=Coord(n,x,y,xinc,res,p)
  180.         x=X
  181.         y=Y
  182.         if btf==0 then
  183.             n=n+1
  184.         end
  185.         xinc=xinc+p
  186.         k=k+1        
  187.     end
  188.     XY=[X,Y]
  189.    
  190. endfunction
  191.  
  192. //utilisation de la fonction incp
  193.  
  194. [XY]=incp(n,x,y,p,nx,xd)
  195.  
  196. disp(XY)
  197.  
  198. //fonction de tracage
  199.  
  200. function graph(XY)
  201.     xset("window",1)
  202.     S=size(XY)
  203.     s=S(1,1)
  204.     k=1
  205.     while k<s
  206.         plot([XY(k,1),XY(k+1,1)],[XY(k,2),XY(k+1,2)])
  207.         k=k+1
  208.     end
  209. endfunction
  210.  
  211. //utilisation de la fonction de tracage
  212.  
  213. graph(XY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement