Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.74 KB | None | 0 0
  1. n=10
  2. x=[0:6/(n-1):6]
  3. xc=[0]
  4. for i=1:n
  5.     xc(i)=3+3*cos(((2*i+1)*%pi)/(2*n))
  6. end
  7. my_y=[0]
  8. for i=1:n
  9.     my_y(i)=exp(sin(x(i)))
  10. end
  11. function Lagrange = Lag(x)
  12.     Lagrange=poly([0],"x","c")
  13.     Li=poly([1],"x","c")
  14.     for i=1:n
  15.         for j=1:n
  16.             if i~=j then
  17.                 li=poly([(-1)*x(j)/(x(i)-x(j));1/(x(i)-x(j))],"x","c")
  18.                 Li=Li*li
  19.                 disp(Li)
  20.             end
  21.         end
  22.         Lagrange=Lagrange+my_y(i)*Li
  23.         Li=poly([1],"x","c")
  24.     end
  25. endfunction
  26. Lagrange = Lag(x)
  27. LagrangeCh = Lag(xc)
  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)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement