Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ans=lagranges(xxx,yyy,xx)
- coeficients=zeros(array(xxx),array(xxx));
- for i=1:array(xxx)
- poly=1;
- denominator=1;
- for j=1:array(xxx)
- if j~=i
- poly=conv(poly,[1 -xxx(j)]);
- denominator=denominator*(xxx(i)-xxx(j));
- end
- end
- coeficients(i,:)=poly/denominator;
- end
- if integrand==1
- ans=coeficients;
- elseif integrand==2
- ans=yyy*coeficients;
- else
- ans=polyval(yyy*coeficients,xx);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement