<!DOCTYPE html>
<html>
<body>
<h1> 例題1-6 牛頓的多項式內插法 </h1>
<p id="demo1">A Paragraph.</p>
<script>
var text='';
var i,j,n=1;
var x=[0 , 1];
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[1][0]=-3;
f[1][1]=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-6 牛頓的多項式內插法
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}
{1.0} ,{1.00}, {-3.00}
=========================
---i------x(i)------f(i)----f(i,i+1)----f(i,i+1.i+2), ......
{0.0} ,{0.00}, {0.00}, {-3.00}
{1.0} ,{1.00}, {-3.00}
沒有留言:
張貼留言