public class Test {static double[][] format;
public static void main(String[] args) {// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.print("輸入插入總點(diǎn)數(shù):");
int n=in.nextInt();//插入點(diǎn)總數(shù)
double[][] xy=new double[2][n];//二維數(shù)組來存儲(chǔ)x和y
for(int j=0;jSystem.out.print("輸入第"+(j+1)+"個(gè)點(diǎn)的x:");
xy[0][j]=in.nextDouble();//第0行放各點(diǎn)的x值
System.out.print("輸入第"+(j+1)+"個(gè)點(diǎn)的y:");
xy[1][j]=in.nextDouble();//第1行放各點(diǎn)的y值
}
creatformat(xy, n);
System.out.println("輸入計(jì)算幾個(gè)點(diǎn):");
int v=in.nextInt();//所求點(diǎn)的總數(shù)
for(int i=0;iSystem.out.println("輸入x= ");
double x=in.nextDouble();
System.out.print("f("+x+")≈"+"Nn("+x+")"+"=");
System.out.printf("%.5f", Nn(xy, n, x));
System.out.println();
}
}
static void creatformat(double[][] xy,int n) {format=new double[n-1][n-1];
for(int i=0;ifor(int j=0;jif(i==0) {format[i][j]=(xy[1][j]-xy[1][j+1])/(xy[0][j]-xy[0][j+1]);
}
else{format[i][j]=(format[i-1][j]-format[i-1][j+1])/(xy[0][j]-xy[0][j+i+1]);
}
}
}
}
static double Nn(double[][] xy,int n,double x) {//牛頓插值公式
double sum=xy[1][0];//求和的初始值為f(X0)
for(int i=0;idouble c=1;
for(int j=0;jc=(x-xy[0][j])*c;
}
sum=sum+format[i][0]*c;
}
return sum;
}
}
運(yùn)行結(jié)果得:
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
分享文章:Java實(shí)現(xiàn)牛頓插值-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://chinadenli.net/article4/doipie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、品牌網(wǎng)站建設(shè)、品牌網(wǎng)站制作、網(wǎng)站內(nèi)鏈、建站公司、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)