2012-07-04 40 views
2

我一直對數學產生函數的多項式,然後改變一個整數集,然後發現組內插多項式。我可以做一套一代C++很好,但我不知道如何模仿Mathematica的Expand[InterpolatingPolynomial[]]命令。我知道這與多項式插值問題有關,我不知道從哪裏開始編寫C++代碼。找到了一組整數

我已經要求Wolfram的MathCode C++的試用版,看看它是否會將它轉換爲我,但我想我寧願自己試試這個,所以任何人都可以指向我正確的方向我該如何開始做這件事?

+0

爲了幫助像我這樣的人不熟悉Mathematica:「展開」是做什麼的? –

+0

@CoffeeonMars展開[expr]擴展expr中的產品和正整數次方。 http://reference.wolfram.com/mathematica/ref/Expand.html –

+0

請參閱[這裏](http://en.wikipedia.org/wiki/Lagrange_polynomial)或[這裏](http://mathworld.wolfram。 com/LagrangeInterpolatingPolynomial.html)爲基本拉格朗日插值公式。 –

回答

0

你可能會想最小二乘法擬合的。這就是你假設一些函數來描述你的數據,然後計算使所有點的均方誤差最小的係數。在Mathematica中尋找它 - 它可以幫助你瞭解你正在尋找的東西的名字。

插值完全是另一回事。

0

可以計算使用僞逆插多項式的一種形式中,這裏是使用近似的Sin函數的順序5的多項式的例子:

(* A function to compute {x^5, x^4, x^3, x^2, x, 1} of x *) 
f = Function[x, x^# & /@ [email protected][0, 5]] 

xvals = [email protected]; 
yvals = Sin /@ [email protected]; 

(* Find the polynomial coefficients by solving the matrix equation *) 
coeffs = PseudoInverse[f /@ xvals].yvals 
poly = {x^5, x^4, x^3, x^2, x, 1}.coeffs 

Plot[{Sin[x], poly}, {x, 0, 10}] 

Mathematica graphics

你可以看到這使輸出作爲InterpolatingPolynomial功能相同:

Simplify[InterpolatingPolynomial[Sin /@ [email protected], x] // N] 
Plot[{Sin[x], %}, {x, 0, 10}] 

Mathematica graphics

這裏Polynomial Interpretation描述的部分的技術構建插值多項式

希望這應該給你足夠的構建工作的C++版本。