Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.70 KB | None | 0 0
  1. n=2
  2. x=[0:6/(n-1):6]
  3. y=0
  4. for i=1:n
  5.     y(i)=5
  6.     //print("F:\y(i).txt",y(i))
  7. end
  8. w=1
  9. function my = My(i)
  10.     my=exp(sin(x(i)))
  11. endfunction
  12.  
  13. function myfunc = Funct(i)
  14.     myfunc=poly([1],"x", "r")
  15.     for j=1:n
  16.         if j~=i
  17.             myfunc1=poly([x(j)/(x(i)-x(j))], "x", "r")
  18.             myfunc = myfunc*myfunc1
  19.         end    
  20.     end
  21. endfunction
  22.  
  23. function Lagrange = Lag()
  24.     Lagrange=poly([0],"x", "c")
  25.     for i=1:n
  26.         yLi=Funct(i)
  27.         my=My(i)
  28.         Lagrange=Lagrange+yLi*my
  29.     end
  30. endfunction
  31.  
  32. Lagrange=Lag()
  33. roots(Lagrange)
  34. _nodes = [0:1/10000:6.1]
  35. value_calc = horner(Lagrange,_nodes)
  36. plot(_nodes, value_calc, "red")
  37. plot(_nodes, exp(sin(_nodes)), "blue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement