Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.89 KB | None | 0 0
  1. n=20
  2. x=[0:6/n:6]
  3. xc=[0]
  4. for i=1:n+1
  5.     xc(i)=3+3*cos(((2*i-1)*%pi)/(2*(n+1)))
  6. end
  7. my_y=[0]
  8. for i=1:n+1
  9.     my_y(i)=exp(sin(x(i)))
  10.     //disp(my_y(i))
  11. end
  12. function Lagrange = Lag(x, n)
  13.     Lagrange=poly([0],"x","c")
  14.     for i=1:n+1
  15.         Li=poly([1],"x","c")
  16.         for j=1:n+1
  17.             if i~=j then
  18.                 li=poly([(-1)*x(j)/(x(i)-x(j)),1/(x(i)-x(j))],"x","c")
  19.                 Li=Li*li
  20.             end
  21.         end
  22.         disp(horner(Li,6))
  23.         Lagrange=Lagrange+my_y(i)*Li
  24.     end
  25. endfunction
  26. Lagrange = Lag(x, n)
  27. LagrangeCh = Lag(xc, n)
  28. _nodes=[0:1/1000:6]
  29. value_calc = horner(Lagrange,_nodes)
  30. value_calcCh = horner(LagrangeCh,_nodes)
  31. plot(_nodes,value_calc)
  32. plot(_nodes,value_calcCh)
  33. plot(_nodes,exp(sin(_nodes)))
  34. disp(horner(Lagrange,6))
  35. disp(horner(LagrangeCh,6))
  36.  
  37. ///////
  38. function Newtoon = Newt(x, n)
  39.     Newtoon=poly([0],"x","c")
  40.    
  41. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement