목차
Linear regression
본문내용
<< \" \" << setprecision(5) << lz[i];
for(i=0;i
{
sumx=sumx+lx[i];
sumy=sumy+ly[i];
sumz=sumz+lz[i];
sumx2=sumx2+lx[i]*lx[i];
sumy2=sumy2+ly[i]*ly[i];
sumxy=sumxy+lx[i]*ly[i];
sumxz=sumxz+lx[i]*lz[i];
sumyz=sumyz+ly[i]*lz[i];
}
cout << \"\\n\" << \"\\n\" << \" ┌ n Σx1i Σx2i ┐ ┌ loga ┐ ┌ Σyi ┐\";
cout << \"\\n\" << \" │ Σx1i Σx1i^2 Σx1ix2i │ │ b │=│Σx1iyi│\";
cout << \"\\n\" << \" ┕ Σx2i Σx1ix2i Σx2i^2 ┘ ┕ c ┘ ┕Σx2iyi┘\";
cout << \"\\n\" << \"\\n\" << \" n = \" << n << \"\\t\" << \" Σx1i = \" << sumx;
cout << \"\\n\" << \" Σx2i = \" << sumy << \"\\t\" << \"Σx1i^2 = \" << sumx2;
cout << \"\\n\" << \" Σx2i^2 = \" << sumy2 << \"\\t\" << \"Σyi = \" << sumz;
cout << \"\\n\" << \" Σx1iyi = \" << sumxz << \"\\t\" << \"Σx2iyi = \" << sumyz;
//cout << \"---------------------------------------------\" << \"\\n\";
//cout << \"Iter\"<< \"\\t\" << \" a\" << \"\\t\" << \" b\" << \"\\t\" << \" c\" << \"\\n\";
//cout << \"---------------------------------------------\"<<\"\\n\" ;
int iter=0;// Gauss-seidel Method
double a,b,c,a0,b0,c0,ea;
b=0,c=0;
while (iter<=1000)
{
iter++;
a=(sumz-sumx*b-sumy*c)/n;
ea=fabs((a-a0)/a*100);
a0=a;
b=(sumxz-sumx*a0-sumxy*c)/sumx2;
b0=b;
c=(sumyz-sumy*a0-sumxy*b0)/sumy2;
c0=c;
if (ea<0.001)
{
//cout << \" \"<< iter << \"\\t\" << a << \"\\t\" << b << \"\\t\" << c << \"\\n\";
//cout << \"---------------------------------------------\"<<\"\\n\";
cout << \"\\n\" << \"\\n\" << \"To find a,b and c, using the Gauss-Seidel method \";
cout << \"\\n\" << \"a = \" << pow(10,a) << \"\\t\" << \"b = \" << b << \"\\t\" << \"c = \" << c;
cout << \"\\n\" << \"Q = \" << pow(10,a) << \" * D^\" << b << \" * S^\" << c;
cout << \"\\n\" << \"\\n\" << \" At D = \" << data1 << \" and S = \" << data2;
cout << \"\\n\" << \" Q = \" << pow(10,a)*pow(data1,b)*pow(data2,c) << \"\\n\";
return ;
}
else
{
//cout<<\" \"<< iter << \"\\t\" << a << \"\\t\" << b << \"\\t\" << c << \"\\n\";
//cout<<\"---------------------------------------------\"<<\"\\n\";
}
}
}
for(i=0;i
sumx=sumx+lx[i];
sumy=sumy+ly[i];
sumz=sumz+lz[i];
sumx2=sumx2+lx[i]*lx[i];
sumy2=sumy2+ly[i]*ly[i];
sumxy=sumxy+lx[i]*ly[i];
sumxz=sumxz+lx[i]*lz[i];
sumyz=sumyz+ly[i]*lz[i];
}
cout << \"\\n\" << \"\\n\" << \" ┌ n Σx1i Σx2i ┐ ┌ loga ┐ ┌ Σyi ┐\";
cout << \"\\n\" << \" │ Σx1i Σx1i^2 Σx1ix2i │ │ b │=│Σx1iyi│\";
cout << \"\\n\" << \" ┕ Σx2i Σx1ix2i Σx2i^2 ┘ ┕ c ┘ ┕Σx2iyi┘\";
cout << \"\\n\" << \"\\n\" << \" n = \" << n << \"\\t\" << \" Σx1i = \" << sumx;
cout << \"\\n\" << \" Σx2i = \" << sumy << \"\\t\" << \"Σx1i^2 = \" << sumx2;
cout << \"\\n\" << \" Σx2i^2 = \" << sumy2 << \"\\t\" << \"Σyi = \" << sumz;
cout << \"\\n\" << \" Σx1iyi = \" << sumxz << \"\\t\" << \"Σx2iyi = \" << sumyz;
//cout << \"---------------------------------------------\" << \"\\n\";
//cout << \"Iter\"<< \"\\t\" << \" a\" << \"\\t\" << \" b\" << \"\\t\" << \" c\" << \"\\n\";
//cout << \"---------------------------------------------\"<<\"\\n\" ;
int iter=0;// Gauss-seidel Method
double a,b,c,a0,b0,c0,ea;
b=0,c=0;
while (iter<=1000)
{
iter++;
a=(sumz-sumx*b-sumy*c)/n;
ea=fabs((a-a0)/a*100);
a0=a;
b=(sumxz-sumx*a0-sumxy*c)/sumx2;
b0=b;
c=(sumyz-sumy*a0-sumxy*b0)/sumy2;
c0=c;
if (ea<0.001)
{
//cout << \" \"<< iter << \"\\t\" << a << \"\\t\" << b << \"\\t\" << c << \"\\n\";
//cout << \"---------------------------------------------\"<<\"\\n\";
cout << \"\\n\" << \"\\n\" << \"To find a,b and c, using the Gauss-Seidel method \";
cout << \"\\n\" << \"a = \" << pow(10,a) << \"\\t\" << \"b = \" << b << \"\\t\" << \"c = \" << c;
cout << \"\\n\" << \"Q = \" << pow(10,a) << \" * D^\" << b << \" * S^\" << c;
cout << \"\\n\" << \"\\n\" << \" At D = \" << data1 << \" and S = \" << data2;
cout << \"\\n\" << \" Q = \" << pow(10,a)*pow(data1,b)*pow(data2,c) << \"\\n\";
return ;
}
else
{
//cout<<\" \"<< iter << \"\\t\" << a << \"\\t\" << b << \"\\t\" << c << \"\\n\";
//cout<<\"---------------------------------------------\"<<\"\\n\";
}
}
}
소개글