⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functionapproximationtest.java

📁 数值分析算法源码(java) 这个学期一边学习java一边学习数值分析,因此用java写了一个数值分析算法的软件包numericalAnalysis. [说明] 适合使用者:会java的
💻 JAVA
字号:
package numericalAnalysis.functionApproximation;

import java.util.Scanner;

public class FunctionApproximationTest {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n;// 拟合数据的点的个数减1
		double[] x, y;// 拟合数据
		FunctionApproximation problem;
		String anotherChoice;// 新的方法
		String another;// 新建一个函数逼近问题的判断
		
		System.out.println("\n----------------------------本程序求解离散情况下的函数逼近问题"
				+ "----------------------------\n\n");
		
		do{
			System.out.println("请输入拟合数据(xi,yi)的点的个数:\n");
			n=input.nextInt()-1;
			
			x=new double[n+1];
			y=new double[n+1];
			
			System.out.println("请输入拟合数据(xi,yi)的xi(用空格分开):\n");
			for(int i=0;i<x.length;i++)
				x[i]=input.nextDouble();
			System.out.println("请输入拟合数据(xi,yi)的yi(用空格分开):\n");
			for(int i=0;i<x.length;i++)
				y[i]=input.nextDouble();
			problem=new FunctionApproximation(n,x,y);
			
			do{
				int choice = 0;
				boolean retry = true;
				while (retry) {
					retry = false;
					System.out.println();
					System.out.println("1---最小平方逼近多项式拟合");
					System.out.println("请选择:");
					try {
						choice = Integer.parseInt(input.next());
					} catch (NumberFormatException e) {
						System.out.println("请别胡乱输入!\n");
						retry = true;
					}
				}
				
				switch(choice){
				case 1:
					System.out.println("请输入最小平方逼近多项式Pm(x)的m:");
					int m=input.nextInt();
					System.out.println("最小平方逼近多项式:");
					System.out.println(problem.leastSquaresApproximation(m));
					break;
				}
				System.out.println("    要再使用其他方法吗?   y/n:");
				anotherChoice = input.next();

			} while (anotherChoice.equalsIgnoreCase("y"));
			
			System.out.println("\n         新建一个函数逼近问题(即输入新的数据(xi,yi))?  y/n:");
			another = input.next();
		} while (another.equalsIgnoreCase("y"));
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -