Here it is matlab-script I build to represent data into linear equation.
function [A] = linierfit(xi,yi)Save it into m-file with name "linierfit.m" in your default matlab folder.
% regresi linear
% y = a0 + a1x
nxi = numel(xi);
nyi = numel(yi);
if nxi ~= nyi
disp('ukuran data tidak sama');
return;
end
n = nxi;
sxi = sum(xi);
xi2 = xi.^2;
sxi2 = sum(xi2);
%matrix X
sigmax = [n sxi;sxi sxi2];
%matrix Y
syi = sum(yi);
xiyi = xi.*yi;
sxiyi = sum(xiyi);
sigmay = [syi;sxiyi];
%matrix A
A = inv(sigmax)*sigmay;
a0 = A(1);
a1 = A(2);
disp('nilai a0 =');
disp(a0);
disp('nilai a1 =');
disp(a1);
yregresi= a0 + a1*xi;
scatter(xi,yi);
hold;
plot(xi,yregresi,'b');
end
Just call "linierfit(x,y)" on your command window.
As long as x (array of independent variable data) and y (array of dependent variable data) have been defined before, the call will result the value of a0 and a1 which are coefficients of linear equation best fit to the data.
JOIN NOW !!!
Dan Dapatkan Bonus yang menggiurkan dari dewalotto.club
Dengan Modal 20.000 anda dapat bermain banyak Games 1 ID
BURUAN DAFTAR!
dewa-lotto.name
dewa-lotto.cc
dewa-lotto.vip