-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch2_9_2.java
More file actions
43 lines (38 loc) · 1.01 KB
/
Copy pathch2_9_2.java
File metadata and controls
43 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.text.DecimalFormat;
public class ch2_9_2
{
static double polynomial2D(double a[][],int m,int n,double x,double y)
{
int i,j;
double result,temp,tt;
result=0.0;
tt=1.0;
for(i=0;i<m;i++) //递推求值
{
temp=a[i][n-1]*tt;
for(j=n-2;j>=0;j--) //内层的递推算法
{
temp=temp*y+a[i][j]*tt;
}
result+=temp;
tt*=x;
}
return result; //返回结果
}
public static void main(String[] args)
{
double result;
double x,y;
DecimalFormat df = new DecimalFormat("0.000E000");
double a[][]={{1.0,2.0,3.0,4.0,5.0}, //初始化二维多项式的系数
{6.0,7.0,8.0,9.0,10.0},
{11.0,12.0,13.0,14.0,15.0},
{16.0,17.0,18.0,19.0,20.0}};
x=0.5; //待求值的点
y=-2.0;
System.out.print("二维多项式求值:\n");
result=polynomial2D(a,4,5,x,y); //调用方法计算
System.out.print("p("+x+","+y+")="+df.format(result)+"\n");
System.out.print("\n");
}
}