利用R语言进行线性/非线性回归拟合实例(1)
1、 生成一组数据
vector<float>xxvec;
vector<float>yyvec;
ofstreamfout("data2.txt");
for (int i =1;i<200;i++)
{
float x =i*0.8;
float randdnum= rand()%10 * 10;
floatrandomflag = (rand()%10)%2==0?(1):(-1);
float y = 3 *x*x + 2*x + 5 + randomflag*randdnum;
fout<<x<<" "<<y<<endl;
xxvec.push_back(x);
yyvec.push_back(y);
}
fout.close();
将生成的数据存为txt文件,命名为“data1