x f(x)
=============
0.0 0.0
1.0 -3.0
2.0 0.0
=============
<!DOCTYPE html>
<html>
<body>
<h1> 例題1-7 牛頓的多項式內插法 </h1>
<h4> ____已知下列3點 座標值____</h4>
<h4> ___i____xi____f(xi)_____ </h4>
<h4> ___0____0 ______0_______ </h4>
<h4> ___1____1 ______-3______ </h4>
<h4> ___2____2 ______0_______ </h4>
<p id="demo1">A Paragraph.</p>
<script>
var text='';
var i,j,n=2;
var x=[0 , 1 ,2];
var f=new Array(2);
for (i=0; i <3; i++)
f[i]=new Array(3)
f[0][0]=0;
f[0][1]=0;
f[0][2]=0;
f[1][0]=-3;
f[1][1]=0;
f[1][2]=0;
f[2][0]=0;
f[2][1]=0;
f[2][2]=0;
text =' Divided Difference Table:<br>';
text+=' =========================<br>';
for(j=1;j<=n;j++){
for(i=0;i<=n-j;i++){
f[i][j]=(f[i+1][j-1]-f[i][j-1])/(x[i+j]-x[i]);
}
//alert(f[i][j].toFixed(2));
}
text+='---i------x(i)------f(i)----f(i,i+1)----f(i,i+1.i+2), ......<br>';
for(i=0;i<=n;i++){
text+='{'+i.toFixed(1)+'}'+' ,{'+x[i].toFixed(2)+'}';
for(j=0;j<=n-i;j++){
text+=', {'+f[i][j].toFixed(2)+'}';
}
text+= '<br>';
}
document.getElementById("demo1").innerHTML=text;
</script>
</body>
</html>
輸出畫面
例題1-7 牛頓的多項式內插法
____已知下列3點 座標值____
___i____xi____f(xi)_____
___0____0 ______0_______
___1____1 ______-3______
___2____2 ______0_______
Divided Difference Table:
=========================
---i------x(i)------f(i)----f(i,i+1)----f(i,i+1.i+2), ......
{0.0} ,{0.00}, {0.00}, {-3.00}, {3.00}
{1.0} ,{1.00}, {-3.00}, {3.00}
{2.0} ,{2.00}, {0.00}
=========================
---i------x(i)------f(i)----f(i,i+1)----f(i,i+1.i+2), ......
{0.0} ,{0.00}, {0.00}, {-3.00}, {3.00}
{1.0} ,{1.00}, {-3.00}, {3.00}
{2.0} ,{2.00}, {0.00}
f(x)= 0 + -3 (x-0) + 3 (x-0) (x-1)
沒有留言:
張貼留言