Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n=20
- x=[0:6/n:6]
- xc=[0]
- for i=1:n+1
- xc(i)=3+3*cos(((2*i-1)*%pi)/(2*(n+1)))
- end
- my_y=[0]
- for i=1:n+1
- my_y(i)=exp(sin(x(i)))
- //disp(my_y(i))
- end
- my_yc=[0]
- for i=1:n+1
- my_yc(i)=exp(sin(xc(i)))
- //disp(my_y(i))
- end
- function Lagrange = Lag(x, my_y, n)
- Lagrange=poly([0],"x","c")
- for i=1:n+1
- Li=poly([1],"x","c")
- for j=1:n+1
- if i~=j then
- li=poly([(-1)*x(j)/(x(i)-x(j)),1/(x(i)-x(j))],"x","c")
- Li=Li*li
- end
- end
- disp(horner(Li,6))
- Lagrange=Lagrange+my_y(i)*Li
- end
- endfunction
- Lagrange = Lag(x, my_y, n)
- LagrangeCh = Lag(xc, my_yc, n)
- _nodes=[0:1/1000:6]
- value_calc = horner(Lagrange,_nodes)
- value_calcCh = horner(LagrangeCh,_nodes)
- plot(_nodes,value_calc, "red")
- plot(_nodes,value_calcCh, "green")
- plot(_nodes,exp(sin(_nodes)), "blue")
- disp(horner(Lagrange,6))
- disp(horner(LagrangeCh,6))
- ///////
- function Newtoon = Newt(x, n)
- Newtoon=poly([0],"x","c")
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement