% Grafy: % Funkce sin(x^2) x=linspace(-3*pi,3*pi); colordef none plot(x,cos(x.^2)) hold on plot(x,cos(x),'g') % Polynomialni aproximace; % Budeme aproximovat oblouk fce cos(x) popsany % malo body pomoci polynomu: x=linspace(-pi/2,pi/2,5) x = -1.5708 -0.7854 0 0.7854 1.5708 format compact y = cos(x); plot(x,y,'o') plot(x,y,'o') n= length(x); V=[ones(n,1),x,x.^2] ??? Error using ==> horzcat All matrices on a row in the bracketed expression must have the same number of rows. x=x.' x = -1.5708 -0.7854 0 0.7854 1.5708 y=y.' y = 0.0000 0.7071 1.0000 0.7071 0.0000 V=[ones(n,1),x,x.^2] V = 1.0000 -1.5708 2.4674 1.0000 -0.7854 0.6169 1.0000 0 0 1.0000 0.7854 0.6169 1.0000 1.5708 2.4674 a=V\y a = 0.9706 0.0000 -0.3954 xx=linspace(-pi/2,pi/2); N=length(xx) N = 100 xx=xx.'; VV=[ones(N,1),xx,xx.^2]; yy=VV*a; hold on plot(xx,yy,'g') plot(xx,cos(xx),'y') % pridame k y nahodne chyby: ys=y+randn(n,1)*0.1; figure plot(x,ys) plot(x,ys,'o') figure plot(x,ys,'o') exit