package .lab8;
import ;
import ;
import .;
public class Newton {
public static double[][] MakeA(double[] t) {
int len = ;
double temp;
double[][] result = new double[len][len];
for (int i = 0; i < len; i++) {
for (int j = 0; j <= i; j++) {
temp = 1;
for (int k = 0; k < j; k++) {
temp *= t[i] - t[k];
}
result[i][j] = temp;
}
}
return result;
}
public static void main(String[] args) {
// 书上例题测试
// double[] t = { -2, 0, 1 };
// double[] y = { -27, -1, 0 };
//实验题目
double[] t = {0,0.5,1.0,6.0,7.0,9.0};
double[] y = {0,1.6,2,2,1.5,0};
double[][] A = MakeA(t);
Print2DArray("A", A);
PrintArray("y", y);
List a = (A);
double[][] L = (double[][]) (0);
double[][] U = (double[][]) (1);
double[] result = (L, U, y);
PrintArray("x", result);
}
/**
* 打印一维数组
*
* @param result
*/
public static void PrintArray(String str, double[] result) {
DecimalFormat df = new DecimalFormat("#.000");
int n = ;
(str + "\n[");
for (int i = 0; i < n; i++) {
((result[i]) + "\t");
}
(']');
();
}
public static void Print2DArray(String str, double[][] result) {
DecimalFormat df = new DecimalFormat("#.000");
int n = ;
int m = result[0].length;
(str + "\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
((result[i][j]) + "\t");
();
}
}
}