最小二乘法线性拟合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 arrayscin>>n;double x[n],y[n],a,b;cout<<"\nEnter the x-axis values:\n"; //Input x-valuesfor (i=0;i>x[i];cout<<"\nEnter the y-axis values:\n"; //Input y-valuesfor (i=0;i>y[i];double xsum=0,x2sum=0,ysum=0,xysum=0; //variables for sums/sigma of xi,yi,xi^2,xiyi etcfor (i=0;i
编译运行:
mkdir build
cd build
cmake ..
make
./linearfit
完整projects下载1。
最小二乘法线性拟合C++ ↩︎
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
