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