Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n=2
- x=[0:6/(n-1):6]
- y=0
- for i=1:n
- y(i)=5
- //print("F:\y(i).txt",y(i))
- end
- w=1
- function my = My(i)
- my=exp(sin(x(i)))
- endfunction
- function myfunc = Funct(i)
- myfunc=poly([1],"x", "r")
- for j=1:n
- if j~=i
- myfunc1=poly([x(j)/(x(i)-x(j))], "x", "r")
- myfunc = myfunc*myfunc1
- end
- end
- endfunction
- function Lagrange = Lag()
- Lagrange=poly([0],"x", "c")
- for i=1:n
- yLi=Funct(i)
- my=My(i)
- Lagrange=Lagrange+yLi*my
- end
- endfunction
- Lagrange=Lag()
- roots(Lagrange)
- _nodes = [0:1/10000:6.1]
- value_calc = horner(Lagrange,_nodes)
- plot(_nodes, value_calc, "red")
- plot(_nodes, exp(sin(_nodes)), "blue")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement