#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> llp;
int main() {
vector<llp> experimental_data;
vector<double> xx,xy;
double sumx = 0, sumy = 0, x, y,a;
int n;
cout<<"请输入共有几组数据 n:";
cin>>n;
cout<<endl;
cout<<"请依次输入xi yi"<<endl;
for (int i = 1; i <= n; i++) {
printf("第 %d 组:",i);
cin >> x >> y;
experimental_data.push_back({x,y});
sumx += x;
sumy += y;
cout<<endl;
}
system("cls");
cout<<"做的很好!以下是您要的表格"<<endl;
printf("———————————我是分界线—————————————\n");
for (int i = 0; i < n; i++) xx.push_back(experimental_data[i].first*experimental_data[i].first);
for (int i = 0; i < n; i++) xy.push_back(experimental_data[i].second*experimental_data[i].first);
printf(" 序号 | x | y | x^2 | x*y |\n");
for (int i = 0; i < n; i++)
printf("第 %d 组 %.3f %.3f %.3f %.3f\n",i+1,experimental_data[i].first,experimental_data[i].second,xx[i],xy[i]);
x = y = 0;
for (int i = 0; i <n; i++) {
x += xx[i];
y += xy[i];
}
sumx/=n*1.0;sumy/=n*1.0;x/=n*1.0;y/=n*1.0;
a=(sumx*sumy-y)/(sumx*sumx-x);
printf("平均值 %.3f %.3f %.3f %.3f\n",sumx,sumy,x,y);
printf("—————————————————————————————————\n");
printf("斜率a=%.3f /%.3f=%.3f\n",sumx*sumy-y,sumx*sumx-x,a);
printf("截距b= %.3f - %.3f * %.3f=%.3f\n",sumy,a,sumx,sumy-a*sumx);
printf("回归方程:y= %.3f x + %.3f" ,a,sumy-a*sumx);
return 0;
}
蒟蒻求求回归曲线求麻了,写个小程序画表格
最新推荐文章于 2024-09-04 10:45:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)