You are on page 1of 1

function [ Y,Z ] = MinimosCuadradosEras( x,y )

%UNTITLED Summary of this function goes here


%
Detailed explanation goes here
N=length(x);
A=[sum(x.^6) sum(x.^5) sum(x.^4) sum(x.^3);sum(x.^5) sum(x.^4) sum(x.^3)
sum(x.^2);sum(x.^4) sum(x.^3) sum(x.^2) sum(x);sum(x.^3) sum(x.^2) sum(x)
N];
D=[sum(x.^3.*y);sum(x.^2.*y);sum(x.*y);sum(y)];
Z=inv(A)*D;
Y=@(X) Z(1).*x.^3+Z(2).*x.^2+Z(3).*x+Z(4);
u=[x(1):0.01:x(N)];
Y1=Y(u);
figure();
plot(x,y,'r'),hold on, grid on, plot(u,Y1,'b');
end

You might also like