久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3555|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

C++多點(diǎn)擬合線代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:233602 發(fā)表于 2017-9-21 10:19 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
//A program finds the best-fitted straight line to the x and y values, and then writes
//the original x, y values and the new y values on the line (for each x) to a data file.
#include<iostream>;                //include the first library
#include<fstream>;                //include the fstream library
using namespace std;        //tell complier that we will use entire namespace standard
void main(void)
{
double ax,ay;                        //declare two double variables
double x[20]={1.0000,2.0000,3.0000,4.0000,5.0000,6.0000,7.0000,8.0000,9.0000,10.0000,11.0000,12.0000,13.0000,14.0000,15.0000,16.0000,17.0000,18.0000,19.0000,20.0000};
                                                //declare a double array with length 20 to store original x values
double y[20]={13.3068,15.0928,16.2509,18.6416,23.6987,27.6380,26.1267,28.4638,33.9061,35.6735,36.0599,39.9298,40.6010,40.0202,43.9743,43.4650,45.7730,50.0811,51.1671,52.4696};
                                                //declare a double array with length 20 to store original y values
double sumx=0, sumy=0;  //declare two double variables
double sub1=0, sub2=0, sumsub1=0, sumsub2=0;
                                                //declare four double variables
double a,b;                                //declare two double variables               
for(int i=0;i<20;i++)        //set a for loop to calculate the sum of original x values
                                                //and the sum of original y values
{
sumx=sumx+x[i];               
sumy=sumy+y[i];               
}
ax=sumx/20;                                //calculate the average of x values
ay=sumy/20;                                //calculate the average of y values
cout<<"The average value of X is:"<<ax<<"\nThe average value of Y is:"<<ay;
                                                //Display the average of all x values and y values

for(int j=0;j<20;j++)        //set a for loop to calculate the component
                                                //of equation of linear regression         to get the value of slope
{
        sub1=(x[j]-ax)*(y[j]-ay);
        sub2=(x[j]-ax)*(x[j]-ax);
        sumsub1=sumsub1+sub1;
        sumsub2=sumsub2+sub2;
}
a=sumsub1/sumsub2;                //the  equation to calculate the slope
                                                //by using the value get from the last for loop
b=ay-a*ax;                                //calculate the value of constant b
cout<<"\nThe value of slope 'a' is:"<<a<<"\nThe value of 'b' is:"<<b;
                                                 //display the value of slope a and the value of constant b
ofstream out("data.dat");//opening a file and output the value of original
                                                 //x, y and new y to a data file named "data.dat"
out<<"x"<<"\t\t"<<"y"<<"\t\t"<<"new y"<<endl;
                                                 //set the format of values display in data file

for(int k=0;k<20;k++)         //set a for loop to display
                                                 //the value of x, y and calculated new y        
{
out<<x[k]<<"\t\t"<<y[k]<<"\t\t"<<a*x[k]+b<<endl;
}
cout<<"\nThe data is output to the file\n";
                                                 //indicate the data is stored in the data file
system("pause");                 //keep the screen otherwise it will appear fast
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日韩视频在线观看一区二区 | 亚洲成人久久久 | 韩国av网站在线观看 | 一本久久a久久精品亚洲 | 免费a网 | 日韩一区二区福利 | 国产午夜精品理论片a大结局 | 免费骚视频 | 国产98色在线| 国产精品综合 | 久久99蜜桃综合影院免费观看 | 成人毛片视频免费 | 欧美日一区二区 | 亚洲成人精品一区 | 在线a视频 | 欧美一区二区三区在线观看 | 一级片av| 亚洲精品久久久一区二区三区 | 一级爱爱片 | 欧美一区二区三区四区视频 | 国产欧美精品一区 | 国产在线一区二区三区 | 久久久久亚洲av毛片大全 | 欧美一区成人 | 91欧美精品成人综合在线观看 | 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 国产偷自视频区视频 | 久久久久久91香蕉国产 | 91精品国产91久久久久久最新 | 国产一区www| 一区二区在线不卡 | 久久精品国产久精国产 | 中文字幕在线观看av | 国产精品夜色一区二区三区 | 中日韩毛片 | 久久免费观看视频 | 欧美日韩在线观看视频网站 | 国产网站在线播放 | 久久99久久99精品免视看婷婷 | 91大神新作在线观看 | 国产日韩一区二区 |