• ベストアンサー

ニュートンの補間多項式と差分商の計算について

こんにちは。下のようなプログラムについての質問です。 ---------------------------------------------------------------- program: Main  (1)integer parameter: n ←9   real array: {Xi}0;n , {Yi}0;n , {Ai}0;n   integer: j,k,n   real: e,h,p   h←1.6875/n   for; k=0 to n do   Xk←k×h   Yk←sin(Xk)   end for  (2)call; Coef(n,{Xi},{Yi},{Ai})   output; {Ai}  (3)for; j=0 to 4×n do   t←(j×h)/4   p←Eval(n,{Xi}(n),{Ai}(n), t)   e←| sin(t)-p |   output; j,t,p,e   end for:  end proguram Main --------------------------------------------------------------- 自分で調べた結果、 (1)について、  Y,Xの点を表に書いて表した。 (2)について、  Coefというのは、差分商計算(ニュートン補間公式の係数)をしなさいという意味。 (3)について、  Evalというのは、値を求めること。 ---------------------------------------------------------------- このプログラムについて質問があります。    1つ目は、(2)の差分商の計算は、全て求める必要はありますか??計算が莫大なので、できるのか不安です。 2つ目は、(3)は、最終的には、[0,1,6875]の範囲にある等間隔の10個の点についてと37個の点についてのニュートンの補間多項式p(x)として、sin(x)とP(x)の誤差を求めているとおもいますが、実際の計算がわかりません。アドバイスお願いします。  

質問者が選んだベストアンサー

  • ベストアンサー
noname#101087
noname#101087
回答No.3

>「前段でも Yk=sin(Xk) の作表に使用しているはずですね。」ということをもう少し説明していただけないでしょうか?... program: Main の前段(1)の中で、Yk の表値を入れてますね。 この記述です。  Yk←sin(Xk) sin(Xk) は正確な正弦値なのでしょう。 そのためのプログラム・モジュールがどこかにあるはず、ということです。

その他の回答 (2)

noname#221368
noname#221368
回答No.2

 横から口を出してすいません。5次以上の補間多項式は、やめておくのが無難だと思うのですが・・・。桁落ち誤差のためです。もちろん多倍長でやるならOKですが、倍精度程度では、4次くらいまでと思っていました。

noname#101087
noname#101087
回答No.1

>...(2)の差分商の計算は、全て求める必要はありますか??計算が莫大なので、できるのか不安です。 >(3)は、最終的には、[0,1,6875]の範囲にある等間隔の10個の点についてと37個の点についてのニュートンの補間多項式p(x)として、 >sin(x)とP(x)の誤差を求めているとおもいますが、実際の計算がわかりません。 (2) (n+1)個の点{X0, X1, X2, .... Xn} でフィットさせるには n次の補間多項式を算定する必要があります。  この例だと、9次多項式を算定せねばなりません。  小手調べに、もっと次数を下げて試行してみるのも一案ですが... 。 (3) sin(t)=sin(j*h/4) は正確な正弦関数を出してくれるモジュール(サブルーチン)が必要です。  前段でも Yk=sin(Xk) の作表に使用しているはずですね。  また、e=|sin(t)-p| のp は、P9(t)=P9(j*h/4) の結果を使うんですよね。  Eval にデータ(n=9, {Ai}, t) を渡せば結果{P9(t)}をもらえるようになっているのではありませんか?  (Eval の中身について。補間多項式Pn(X)の次数n・係数セット{Ai}・変数値{X=t} をもらってPn(t)を算定するものだと考えてます)

Lovechild0
質問者

補足

「前段でも Yk=sin(Xk) の作表に使用しているはずですね。」ということをもう少し説明していただけないでしょうか??すみません。

関連するQ&A

  • 補間についてのプログラム。

    こんにちは。補間についての本を読んでいての質問なのですが、 ---------------------------------------------------------- program: Main integer parameter: n ←9 real array: {Xi}0;n , {Yi}0;n , {Ai}0;n integer: j,k,n real: e,h,p h←1.6875/n for; k=0 to n do Xk←k×h Yk←sin(Xk) end for call; Coef(n,{Xi},{Yi},{Ai}) output; {Ai} for; j=0 to 4×n do t←(j×h)/4 p←Eval(n,{Xi}(n),{Ai}(n), t) e←| sin(t)-p | output; j,t,p,e end for: end proguram Main ---------------------------------------------- とあったのですが、どのように訳していけばよいのでしょうか??アドバイスお願いします!

  • 逆数補間の計算方法について

    こんにちは。前にも書かせてもらいましたが、どうしても計算ができないので、もう一度質問させてもらいました。 以下のような、洋書を読んで、最後にあるP(y)を出したいのですが、計算方法がわかりません。 ---------------------------------------------------------------- [Inverse Interpolation] A process called inverse interpolation is often used to approximate an inverse function. Suppose that values {Yi}=f({Xi}) have been computed at X0,X1,...,Xn. Using table Y ; Y0 Y1 Y2 ......Yn X ; X0 X1 X2 ......Xn we form the interpolation polynomial p(y)=Σ(i=1→n)CiΠ(j=0→i-1){Y-Yj} The orijinal relationship, y=f(x), has an inverse, under certain conditions. This inverse is being approximated by x=p(y). Procedures Coef and Eval can be used to carry out the inverse interpolation by reversing the arguments x and y in the calling sequence for Coef. Inverse interpolation can be used to find where a given functuin f has a root or zero. This means inverting the equation f(x)=0. We propose to do this by creating a table of values (f(Xi),Xi) and interpolating with a polynomial,p. Thus, p(Yi)=Xi. The points Xi should be chosen near the unknown root,r. The approximate root is then given by r ~p(0). For a concrete case, let the table of known values be Y;-0.5789200,-0.3626370,-0.1849160,-0.0340642,0.0969858 X; 1.0 , 2.0 , 3.0 , 4.0 , 5.0 The nodes in this problem are the points in the row of the table headed y, and the function values being interpolated are in the x row. The resulting polynomial is p(Y)=0.25Y^4+1.2Y^3+3.69Y^2+7.39Y+4.247470086 and p(0)=4.247470086. Only the last coefficient is shown with all the digits carried in the calculation, for it is the only one needed for the problem at hand. ---------------------------------------------------------------- <補足>CoefとEvalについて 「 procedure; Coef(n,{Xi},{Yi},{Ai}) real array; {Xi}0:n, {Yi}0:n, {Ai}0:n integer; i,j,n for i=0 to n do {Ai}←{Yi} end for for j=1 to n do for i=n to j step -1 do Ai←({Ai}-{Ai-1})/({Xi}-{Xi-j}) end for end for end procedure Coef 」 「 real function; Eval(n,{Xi},{Yi},{Ai}) real array; {Xi}0:n, {Ai}0:n integer; i,n real;t,temp temp←An for i=n-1 to 0 step -1 do temp←(temp)(t-{Xi})+{Ai} end for Eval←temp end function Eval」 ------------------------------------------------------------- XとYを扱い方がよくわかっていないので、計算できないのかなあと思います。分かる方、アドバイスお願いします(泣)

  • プログラムに内容と計算の質問です。

    こんにちは。 補間多項式についての、コンピュータのプログラムの解読に困っています。内容は、 「For the numerical experiments suggested in the computer problems, the following two procedures should be satisfactory. The first is called Coef. It requires as input the number n and tabular values in the array {Xi} and {Yi}. Remember that the number of points in the table is n+1. The procedure then computes the coefficients required in the Newton interpolating polynomial, storing them in the array{Ai}. -------------------------------------------------------- procedure; Coef(n,{Xi},{Yi},{Ai}) real array; {Xi}0:n, {Yi}0:n, {Ai}0:n integer; i,j,n for i=0 to n do {Ai}←{Yi} end for for j=1 to n do for i=n to j step -1 do Ai←({Ai}-{Ai-1})/({Xi}-{Xi-j}) end for end for end procedure Coef --------------------------------------------------------- このプログラムのn=3の時を考えるとき、  (1)j=1のとき、i=3,2,1 <j=1,i=1> {A1}=({A1}-{A0})/({X1}-{X0}) =({Y1}-{Y0})/({X1}-{X0}) <i=1,i=2> {A2}=({A2}-{A1})/({X2}-{X1}) =({Y2}-{Y1})/({X2}-{X1}) <i=1,i=3> {A3}=({A3}-{A2})/({X3}-{X2}) =({Y3}-{Y2})/({X3}-{X2}) (2)j=2のとき、i=3,2 <j=2,i=1> A1=({A2}-{A1})/({X2}-{X0})          ={[({Y2}-{Y1})/({X2}-{X1})]-[({Y1}-{Y0})/({X1}-{X0})]}/({X2}-{X0}) =この式変形をしたいのですが、どのように         すれば良いのかわかりません。ラグランジェ         型になりそうでなりません(泣)         (1)で求めた{A1},{A2},{A3}を使って求めな         いといけないみたいです。 見にくい表し方で申し訳ありません。 アドバイスお願いします!!

  • 逆関数の補間について

    こんにちは。前に質問させてもらい、計算については 理解できました。しかし、以下の文章のある部分の意味がわかりません。まず、文章は、 [Inverse Interpolation] A process called inverse interpolation is often used to approximate an inverse function. Suppose that values {Yi}=f({Xi}) have been computed at X0,X1,...,Xn. Using table Y ; Y0 Y1 Y2 ......Yn X ; X0 X1 X2 ......Xn we form the interpolation polynomial p(y)=Σ(i=1→n)CiΠ(j=0→i-1){Y-Yj} The orijinal relationship, y=f(x), has an inverse, under certain conditions. This inverse is being approximated by x=p(y). Procedures Coef and Eval can be used to carry out the inverse interpolation by reversing the arguments x and y in the calling sequence for Coef. Inverse interpolation can be used to find where a given functuin f has a root or zero. This means inverting the equation f(x)=0. We propose to do this by creating a table of values (f(Xi),Xi) and interpolating with a polynomial,p. Thus, p(Yi)=Xi. The points Xi should be chosen near the unknown root,r. The approximate root is then given by r ~p(0). For a concrete case, let the table of known values be Y;-0.5789200,-0.3626370,-0.1849160,-0.0340642,0.0969858 X; 1.0 , 2.0 , 3.0 , 4.0 , 5.0 The nodes in this problem are the points in the row of the table headed y, and the function values being interpolated are in the x row. The resulting polynomial is p(Y)=0.25Y^4+1.2Y^3+3.69Y^2+7.39Y+4.247470086 and p(0)=4.247470086. Only the last coefficient is shown with all the digits carried in the calculation, for it is the only one needed for the problem at hand. ---------------------------------------------------------------- <補足>CoefとEvalについて 「 procedure; Coef(n,{Xi},{Yi},{Ai}) real array; {Xi}0:n, {Yi}0:n, {Ai}0:n integer; i,j,n for i=0 to n do {Ai}←{Yi} end for for j=1 to n do for i=n to j step -1 do Ai←({Ai}-{Ai-1})/({Xi}-{Xi-j}) end for end for end procedure Coef 」 「 real function; Eval(n,{Xi},{Yi},{Ai}) real array; {Xi}0:n, {Ai}0:n integer; i,n real;t,temp temp←An for i=n-1 to 0 step -1 do temp←(temp)(t-{Xi})+{Ai} end for Eval←temp end function Eval」 ------------------------------------------------------------- です。この文章の 「The orijinal relationship, y=f(x), has an inverse, under certain conditions. This inverse is being approximated by x=p(y). Procedures Coef and Eval can be used to carry out the inverse interpolation by reversing the arguments x and y in the calling sequence for Coef. Inverse interpolation can be used to find where a given functuin f has a root or zero. This means inverting the equation f(x)=0. We propose to do this by creating a table of values (f(Xi),Xi) and interpolating with a polynomial,p. Thus, p(Yi)=Xi. The points Xi should be chosen near the unknown root,r. The approximate root is then given by r ~p(0).」 という部分が理解できません。わかる方アドバイスお願いします(泣)

  • ラグランジュ補間多項式

    何回でも微分できる関数f(x)とし、 x0,x1,x2,x3,x4を刻幅hの等間隔分点としたとき(xk=x0+kh) f(x)のラグランジュ補間p4(x)を求めて ∫[x0,x4]p4(x)dx = 2h/45(7f(x0)+32f(x1)+12f(x2)+32f(x3)+7f(x4)) となることを示したいのですが p4(x)を求めて積分しようと思っているのですが p4(x)の式がラグランジュ補間のとおりにやるとすごく長い式になってしまし 積分するにあたって多項式の形にしようとしてるのですがよくできません 教えてください。

  • 数値解析の補間多項式

    (1)nを1以上の整数とし,X0,X1,,,Xnを相異なるn+1個の標本点とする。R上の関数f,g,hにおいて、gはfをX0,X1,,,Xn-1で補間し(つまり,g(Xi)=f(Xi),i=0,1,2,,,,n-1となる)、hはfをX1,,,Xnで補間するとき、関数    g(X)+(X0ーX)/(Xn-X0)×{g(X)ーh(X)} は、fをX0,X1,,,Xnで補間することを示したのですが質問があります。 まず補間するということはどんな意味を持っているのでしょうか?そしてこの問題の但し書きとしてf,g,hは多項式とは限らないとあったのですがではどう考えたらよいのでしょうか?? 最終的にどのように証明していけばよいかアドバイスお願いします★

  • n次多項式についての質問です

    n 次以下の多項式P(x)=anxn + an-1xn-1 + ··· + a1x + a0の計算について、 P(x)を計算するために以下のようなアルゴリズムを考えました S←0; for i=0,,,,n do X←1; for j=1,,,,,i do X←X*x endfor; S←S+X*ai end for ※Sには上の多項式が入ります このアルゴリズムが正しいことの説明と、 アルゴリズムの計算回数を求めたいのですが いまいちわかりません。 教えてください。

  • ラグランジュの補間法のCプログラム

    昨日学校でラグランジュの補間法の問題をC言語のプログラムで解けという課題が出されました しかし、友達と相談してもよくわかりませんでした 課題は以下の問題です sin関数6点、(0.92+0.01x)、x=0,1,2,3,4,5を求めて、ラグランジュの方法でsin(0.923)を計算せよ ちなみに答えは、0.79742です 先生からサンプルのプログラムをもらいました 以下のサンプルプログラムを参考にして解いてくださいと言われたのですが、どうしても解けません すいませんが分かる方、よろしくお願いします #include <stdio.h> #include <math.h> #define N 6 //データ数 double x[N]={ 0.0,1.0,2.0,3.0,3.1,5.0}; //X座標 double y[N]={0.0,1.1,2.5,4.0,4.1,5.0}; //Y座標 double lagrange( double); int main() { double xx,yy; //補間計算 printf("XX\t\tYY\n"); for( xx=0.0; xx<=5.0; xx+=.2 ) { yy = lagrange( xx); printf("%8.2lf\t%8.2lf\n", xx, yy ); } return 0; } //補間サブルーチン double lagrange( double xx ) { double z[N]; double yy=0.0; int i,j; for( i=0; i<N; i++ ) { z[i] = 1.0; //係数計算 for( j=0; j<N; j++ ) if( i!=j ) z[i]*=(xx-x[j])/(x[i]-x[j]); //補間値計算 yy+=z[i]*y[i]; } return yy; } 上記はあくまでサンプルプログラムなので、中に入っている数値は適当です よろしくお願いします

  • 補間多項式

    「相異なる点、x_0,x_1,・・・・,x_nに対して、任意の実数y_0,y_1,・・・,y_nがある。そのときp_n+1(x_i)=y_i(i=0,1,・・・,n)を満たす高々n+1次の補間多項式p_n+1がただ一つ存在する。」は真か偽を判定する問題です。考えたのですが偽でしょうか?定義は「与えられた関数y=f(x)に対して、相異なる点x_0,・・・,x_n-1(この点を標本点という)について、y_k=f(x_k),k=0,1,・・・,n-1とおく。このとき高々n-1次多項式p(x)としてp(x_k)=y_k,k=0,1,・・・,n-1となるものがある」理由はやはり高々n+1次というところが定義からづれているからです。しかし根拠が示せないので、アドバイスありましたら嬉しいです・・・

  • 大学数学の問題です

    勉強不足でわかりません。得意な方、解答お願いいたします。 問1 補間点をX0=1,X1=2,X2=3,とし、これらの補間点での関数値をf0=4, f1=-3, f2=2とする。ラグランジュ補間多項式をP(X)=A(x-2)(x-3)+B(x-1)(x-3)+C(x-1)(x-2)と表したとき、A,B,Cに入る値を求めよ。 問2 関数f(x)=x^3-1に対するニュートン法の式をxk+1=xk-Aとする。Aを書き表せ。※k+1、kは1/4下付文字 問3 n=4としてa1=2、a2=3、a3=-2、a4=5が与えられたとき、以下の疑似コードを実行するとa1,a2,a3,a4はどうなるか。 for i =1,2,…,n-1 do if ai<ai+1 then t ← ai+1 ai+1 ← ai ai+1 ← t end if end for ※疑似コードのi、i+1は1/4下付文字