Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.01 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. my_yc=[0]
  13. for i=1:n+1
  14.     my_yc(i)=exp(sin(xc(i)))
  15.     //disp(my_y(i))
  16. end
  17. function Lagrange = Lag(x, my_y, n)
  18.     Lagrange=poly([0],"x","c")
  19.     for i=1:n+1
  20.         Li=poly([1],"x","c")
  21.         for j=1:n+1
  22.             if i~=j then
  23.                 li=poly([(-1)*x(j)/(x(i)-x(j)),1/(x(i)-x(j))],"x","c")
  24.                 Li=Li*li
  25.             end
  26.         end
  27.         disp(horner(Li,6))
  28.         Lagrange=Lagrange+my_y(i)*Li
  29.     end
  30. endfunction
  31. Lagrange = Lag(x, my_y, n)
  32. LagrangeCh = Lag(xc, my_yc, n)
  33. _nodes=[0:1/1000:6]
  34. value_calc = horner(Lagrange,_nodes)
  35. value_calcCh = horner(LagrangeCh,_nodes)
  36. plot(_nodes,value_calc, "red")
  37. plot(_nodes,value_calcCh, "green")
  38. plot(_nodes,exp(sin(_nodes)), "blue")
  39. disp(horner(Lagrange,6))
  40. disp(horner(LagrangeCh,6))
  41.  
  42. ///////
  43. function Newtoon = Newt(x, n)
  44.     Newtoon=poly([0],"x","c")
  45.    
  46. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement