最小二乘法线性拟合C++

使用C++进行最小二乘法线性拟合。

CMakeLists:

cmake_minimum_required(VERSION 2.8)
project(linearfit)
add_executable (linearfit main_linearfit.cpp)
target_link_libraries (linearfit)

C++代码:

//Linear Fit
#include
#include
#include
using namespace std;
int main()
{
    int i,j,k,n;
    cout<<"\nEnter the no. of data pairs to be entered:\n";        //To find the size of arrays
    cin>>n;
    double x[n],y[n],a,b;
    cout<<"\nEnter the x-axis values:\n";                //Input x-values
    for (i=0;i>x[i];
    cout<<"\nEnter the y-axis values:\n";                //Input y-values
    for (i=0;i>y[i];
    double xsum=0,x2sum=0,ysum=0,xysum=0;                //variables for sums/sigma of xi,yi,xi^2,xiyi etc
    for (i=0;i

编译运行:

mkdir build
cd build
cmake ..
make
./linearfit

完整projects下载1


  1. 最小二乘法线性拟合C++ ↩︎

你可能感兴趣的:(Math,Research)