Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Artur Wi�niewski g.6 lab.10 zad. 5 opcja 3
- x=[-12, -9, -6, -2, 1, 4, 6, 8, 9, 12];
- y=[3, -1, -4, -2, 2, 2, 7, 1, 0, 5];
- if length(x)==length(y)
- stopien=7;
- n=length(x);
- X=zeros(stopien+1,stopien+1);
- A=zeros(stopien+1,1);
- Y=zeros(stopien+1,1);
- suma = 0;
- potega = 0;
- for i=1:stopien+1
- for j=1:stopien+1
- for k=1:n
- suma = suma + x(k)^potega;
- end
- potega = potega + 1;
- X(i,j)=suma;
- end
- suma = 0;
- potega = i;
- end
- disp("Macierz X");
- disp(X);
- sumaY = 0;
- potegaY = 0;
- for i=1:stopien+1
- for k=1:n
- sumaY = sumaY + (x(k)^potegaY * y(k));
- end
- potegaY = potegaY + 1;
- Y(i,1) = sumaY;
- end
- disp("Macierz Y");
- disp(Y);
- A=inv(X)*Y;
- disp("Macierz A");
- disp(A);
- Q=polyfit(x, y, stopien);
- yi=zeros(1,n);
- for i=1:n
- yi(1,i)=0;
- for j=1:stopien+1
- yi(1,i)=yi(1,i) + Q(1,j)*x(1,i)^(stopien+1-j);
- end
- end
- plot(x,y, 'bx--');
- grid on;
- hold on;
- plot(x,yi, 'ro--');
- else
- disp("Liczba wsp��rz�dnych x nie jest r�wna liczbie wsp��rz�dnych y");
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement