You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
2 years ago | |
---|---|---|
README.md | 2 years ago |
README.md
numerical_analysis
import java.util.Scanner; /*
-
X表示插入点的横坐标
-
x[i]表示已知点的横坐标
-
y[i]表示已知点的纵坐标
-
l0、l1表示插值的基本函数
-
p表示插座多项式
-
/ public class Lagrange_Interpolate { public static double lagrange_interpolate(double x[],double y[],double X,int n) { double p=0.0; double l0 = (X-x[1])/(x[0]-x[1]); double l1 = (X-x[0])/(x[1]-x[0]); p = l0y[0]+l1*y[1]; return p; }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("已知结点个数:"); int n = sc.nextInt(); System.out.println("输入已知水深度与其对应温度"); double []x = new double[n] ; double []y = new double[n] ; for(int i=0;i<n;i++) { x[i] = sc.nextDouble(); y[i] = sc.nextDouble(); } System.out.print("输入所求温度的深度:"); double X = sc.nextInt(); System.out.println("结果为:"+lagrange_interpolate(x,y,X,n));
} }