我正在試圖找到一組x和y數據的多項式迴歸。我下載了下面的模板來這樣做,但我不知道如何調用它,並且我的嘗試遇到了錯誤LNK2019:無法解析的外部符號。如何調用模板中定義的函數
#pragma once
#ifdef BOOST_UBLAS_TYPE_CHECK
# undef BOOST_UBLAS_TYPE_CHECK
#endif
#define BOOST_UBLAS_TYPE_CHECK 0
#ifndef _USE_MATH_DEFINES
# define _USE_MATH_DEFINES
#endif
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/lu.hpp>
#include <vector>
#include <stdexcept>
/*
Finds the coefficients of a polynomial p(x) of degree n that fits the data,
p(x(i)) to y(i), in a least squares sense. The result p is a row vector of
length n+1 containing the polynomial coefficients in incremental powers.
param:
oX x axis values
oY y axis values
nDegree polynomial degree including the constant
return:
coefficients of a polynomial starting at the constant coefficient and
ending with the coefficient of power to nDegree. C++0x-compatible
compilers make returning locally created vectors very efficient.
*/
template<typename T>
std::vector<T> polyfit(const std::vector<T>& oX,
const std::vector<T>& oY, int nDegree)
{
...
}
我不認爲你們大家需要的模板的其餘部分來幫助我,但如果有必要,我將它張貼。 (它來自這個網站http://vilipetek.com/2013/10/07/polynomial-fitting-in-c-using-boost/)如果有一個更好/更容易的工具,讓我知道它。
這是我試圖運行它: 宣言
std::vector<int> polyfit(const std::vector<int> xsplinevector,
const std::vector<int> ysplinevector,
函數調用
polynomial = polyfit((xsplinevector), (ysplinevector), 4);
int nDegree);
你爲什麼要重新 - 宣佈它?這具有宣告你沒有實現的專業化的效果,因此沒有解決的符號。 – tadman 2014-09-10 17:03:02
@tadman也許這是錯誤的術語。爲了在另一個方法中使用方法,您是否必須具有上述方法的頭部? – user3241316 2014-09-10 17:07:00
哪個錯誤(完整的描述)? – Amadeus 2014-09-10 17:13:56