Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a=0.3;
- b=8.7;
- n=10;
- pol=2;
- h=(b-a)/10;
- x1=h*(b+a);
- x2=0.3*(b-a)+2*h;
- f=@(x) (sin(x)+0.5*cos(2*x)+0.5*x);
- x = zeros(1,n);
- y = zeros(1,n);
- for i=1:n
- x(i)=a+i*h;
- y(i)=f(a+i*h);
- end;
- for pol_st=1:5
- xx=linspace(min(x),max(x),pol);
- pol=pol+1;
- yy=0;
- for i=1:n
- P=1;
- for k=1:n
- if(i~=k)
- P=P.*(xx-x(k))./(x(i)-x(k));
- %.* - поэлементное умножение
- %./ - поэлементное деление
- end
- end
- yy=yy+y(i)*P;
- end
- plot(xx,yy);
- hold on;
- end
- fplot( '[sin(x)+0.5*cos(2*x)+0.5*x]',[0.3 8.7],0.0001)
- plot(x,y,'*r');
- grid on
- plot(xx,yy,'bo');
- %legend('sin(5*x)/x','{\itL_n}({\itx})','nodes',-1)
- legend('pol=1','pol=2','pol=3','pol=4','pol=5','sin(x)+0.5*cos(2*x)+0.5*x','nodes:x,y' ,'nodes:xx,yy');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement