日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Neville 插值方法

發布時間:2025/3/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Neville 插值方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

wikipedia: Neville's method

在數學上,Neville 算法是一種計算插值多項式方法,由數學家Eric Harold Neville提出。由給定的n+1個節點,存在一個唯一的冪次≤n的多項式存在,并且通過給定點。

算法

給定n+1個節點及其對應函數值 \((x_i, y_i)\),假設 \(P_{i,j}\) 表示 \(j-i\) 階多項式,并且滿足通過節點 \((x_k, y_k) \quad k =i, i+1, \cdots, j\)。\(P_{i,j}\) 滿足以下迭代關系

\[\begin{eqnarray} \begin{aligned} & p_{i,i}(x) = y_i \cr & P_{i,j}(x) = \frac{(x_j - x)p_{i,j-1}(x) + (x - x_i)p_{i+1,j}(x)}{x_j - x_i}, \quad 0\le i\le j \le n \end{aligned} \end{eqnarray}\]

以n=4的節點舉例,其迭代過程為

\[\begin{eqnarray} \begin{aligned} & p_{1,1}(x) = y_1, \cr & p_{2,2}(x) = y_2, p_{1,2}(x), \cr & p_{3,3}(x) = y_3, p_{2,3}(x), p_{1,3}(x),\cr & p_{4,4}(x) = y_4, p_{3,4}(x), p_{2,4}(x), p_{1,4}(x)\cr \end{aligned} \end{eqnarray}\]

代碼

偽代碼

  • 由于計算插值點為一向量,為避免過多層循環嵌套,將每個 \(P_{i,j}\) 都改寫為向量形式,各元素分別儲存多項式在插值點 \(x_0\) 處函數值。
  • 只有每次當一列 \(P_{i,j}\) 計算完后,才能利用迭代公式計算下一列 \(P_{i,j}\) 多項式,因此外層循環為計算每列 \(P_{i,j}\) 多項式。
  • 每列 \(P_{i,j}\) 個數是逐漸減少的,最開始有n個多項式,最終循環只有一個。

可將矩陣P[nRow,nCol]用于存儲多項式 \(P_{i,j}(x)\)。其中每行為 \(P_{i,j}(x_k)\) 在 nCol 個插值點\(x_k\)處函數值。每次外層循環 \(P_{i,j}(x)\) 個數減少,此時從最后一行開始舍棄,每次只循環

for irow = 1: (nRow - icol) %

\(x_i\)\(x_j\)分別用變量x1與x2代替。迭代公式可表示為

for icol = 1:nRow - 1for irow = 1: (nRow - icol) % x1 = nodes(irow); x2 = nodes(irow + icol);P(irow, :) = ( (x2 - x0).*P(irow, :) + (x0 - x1 ).*P(irow+1, :) )./( x2 - x1 );end% for end% for

最終完整代碼為

function evalPol = f1300000_Neville(x0, nodes, fnodes) % Implement Neville's algorithm to evaluate interpolation polynomial at x0 % Input: % x0 - the point where we want to evaluate the polynomial % nodes - vector containing the interpolation nodes % fnodes - vector containing the values of the function % Output: % evalPol - vector containing the value at x0 of the different % the interpolating polynomialsif iscolumn(x0)x0 = x0'; % transfer to row vector endif isrow(fnodes)fnodes = fnodes'; endnCol = length(x0); nRow = length(nodes);% P = zeros(nRow, nCol); P = repmat(fnodes, 1, nCol);for icol = 1:nRow - 1for irow = 1: (nRow - icol) % x1 = nodes(irow); x2 = nodes(irow + icol);P(irow, :) = ( (x2 - x0).*P(irow, :) + (x0 - x1 ).*P(irow+1, :) )./( x2 - x1 );end% for end% forevalPol = P(1,:); end

轉載于:https://www.cnblogs.com/li12242/p/5047042.html

總結

以上是生活随笔為你收集整理的Neville 插值方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。