Linear regression to pieces in matlab

0

Hi, I would like you to help me in this. This is what I have been able to tell me if I am going well or not and if so, what should I do please:

function:

function [m,b,error, yApp]=f_regresionLineal(x,y)

xp = mean(x); yp = mean(y); n = length(x);

m = ( sum(x.y) -nxpyp )/( sum(x.^2)-nxp^2 ); b = yp-m*xp;

yApp = m*x+b; error = mean(abs(y-yApp)./y);

end

script:

xS = linspace(0,2*pi,25); yS = sin(xS)+2;

plot(xS,yS,'r*') grid on axis tight hold on

xxS=xS(1:8); yyS=yS(1:8); [m,b,error, yApp]=f_regresionLineal(xxS,yyS) hold on; plot(xxS,yApp,'b');

xxS=xS(8:18); yyS=yS(8:18); [m,b,error, yApp]=f_regresionLineal(xxS,yyS) hold on; plot(xxS,yApp,'g');

xxS=xS(18:22); yyS=yS(18:22); [m,b,error, yApp]=f_regresionLineal(xxS,yyS) hold on; plot(xxS,yApp,'k');

xxS=xS(22:25); yyS=yS(22:25); [m,b,error, yApp]=f_regresionLineal(xxS,yyS) hold on; plot(xxS,yApp,'y');
    
asked by Andres 25.04.2018 в 16:00
source

0 answers