function [ pP,bod ] = dga_duval_rozdily( t,X_CH4,X_C2H2,X_C2H4,tau,out,k)
clc
[tspol,CH4spol,C2H2spol,C2H4spol,l]=vyhazet_radky3(t,X_CH4,X_C2H2,X_C2H4);
n=length(tspol);

if out==1;
    [Q1,I1]=outliers([tspol CH4spol],1.5);
    tCH4=Q1(:,1);
    XCH4=Q1(:,2);
else
    tCH4=tspol;
    XCH4=CH4spol;
end;

if out==1;
    [Q2,I2]=outliers([tspol C2H4spol],1.5);
    tC2H4=Q2(:,1);
    XC2H4=Q2(:,2);
else
    tC2H4=tspol;
    XC2H4=C2H4spol;
end;

if out==1;
    [Q3,I3]=outliers([tspol C2H2spol],1.5);
    tC2H2=Q3(:,1);
    XC2H2=Q3(:,2);
else
    tC2H2=tspol;
    XC2H2=C2H2spol;
end;

if k==1;
    b_lin=robustfit(tCH4,XCH4);
    b_lin1=robustfit(tC2H4,XC2H4);
    b_lin2=robustfit(tC2H2,XC2H2);
    y(1)=b_lin(1)+b_lin(2)*tau;
    y(2)=b_lin1(1)+b_lin1(2)*tau;
    y(3)=b_lin2(1)+b_lin2(2)*tau;
end;    
if k==2;
    b_moc=robustfit(log(tCH4),log(XCH4));
    b_moc1=robustfit(log(tC2H4),log(XC2H4));
    b_moc2=robustfit(log(tC2H2),log(XC2H2));
    y(1)=exp(b_moc(1))*(tau^b_moc(2));
    y(2)=exp(b_moc1(1))*(tau^b_moc1(2));
    y(3)=exp(b_moc2(1))*(tau^b_moc2(2));
end; 
if k==3;
    f1=fit(tCH4,XCH4,'poly1');
    f11=fit(tC2H4,XC2H4,'poly1');
    f12=fit(tC2H2,XC2H2,'poly1');
    b5=coeffvalues(f1);
    b51=coeffvalues(f11);
    b52=coeffvalues(f12);
    y(1)=b5(2)+b5(1)*tau;
    y(2)=b51(2)+b51(1)*tau;
    y(3)=b52(2)+b52(1)*tau;
end;
if k==4;
    f2=fit(tCH4,XCH4,'exp1');
    f21=fit(tC2H4,XC2H4,'exp1');
    f22=fit(tC2H2,XC2H2,'exp1');
    b2=coeffvalues(f2);
    b21=coeffvalues(f21);
    b22=coeffvalues(f22);
    y(1)=b2(1)*exp(b2(2)*tau);
    y(2)=b21(1)*exp(b21(2)*tau);
    y(3)=b22(1)*exp(b22(2)*tau);
end;
if k==5;
    r=ksr(tCH4,XCH4);
    r1=ksr(tC2H4,XC2H4);
    r2=ksr(tC2H2,XC2H2);
    f3=fit(tCH4,r.f','poly2');
    f31=fit(tC2H4,r1.f','poly2');
    f32=fit(tC2H2,r2.f','poly2');
    b3=coeffvalues(f3);
    b31=coeffvalues(f31);
    b32=coeffvalues(f32);
    y(1)=b3(1)*tau^2+b3(2)*tau+b3(3);
    y(2)=b31(1)*tau^2+b31(2)*tau+b31(3);
    y(3)=b32(1)*tau^2+b32(2)*tau+b32(3);
end;
if k==6;
    klp=smooth(XCH4,3);
    klp1=smooth(XC2H4,3);
    klp2=smooth(XC2H2,3);
    f4=fit(tCH4,klp,'poly2');
    f41=fit(tC2H4,klp1,'poly2');
    f42=fit(tC2H2,klp2,'poly2');
    b4=coeffvalues(f4);
    b41=coeffvalues(f41);
    b42=coeffvalues(f42);
    y(1)=b4(1)*tau^2+b4(2)*tau+b4(3);
    y(2)=b41(1)*tau^2+b41(2)*tau+b41(3);
    y(3)=b42(1)*tau^2+b42(2)*tau+b42(3);
end;

soucet1=CH4spol(n)+C2H2spol(n)+C2H4spol(n);
soucet2=sum(y);
dif1=abs(y(1)-CH4spol(n));
dif2=abs(y(2)-C2H4spol(n));
dif3=abs(y(3)-C2H2spol(n));
dif=abs(soucet2-soucet1);






end

