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

📄 norm.java

📁 数学:数值分析:线性方程组 线性方程组的多种解法
💻 JAVA
字号:
package linearEquationGroup;

//********************************************************************
//Norm.java       Author: GaoXishan
//
//compute the norm of a vector or a matrix(not finished).
//********************************************************************

public class Norm {
	// ----------------------------------------------------------------------------------------
	// Compute the one-norm of a vector.
	// ----------------------------------------------------------------------------------------
	public static double vectorOne(int n, double[] vector) {
		double sum = 0;
		for (int i = 1; i < n + 1; i++)
			sum += Math.abs(vector[i]);

		return sum;
	}

	// ----------------------------------------------------------------------------------------
	// Compute the two-norm of a vector.
	// ----------------------------------------------------------------------------------------
	public static double vectorTwo(int n, double[] vector) {
		double sum = 0;
		for (int i = 1; i < n + 1; i++)
			sum += Math.pow(vector[i], 2);

		return Math.sqrt(sum);
	}

	// ----------------------------------------------------------------------------------------
	// Compute the infinitive-norm of a vector.
	// ----------------------------------------------------------------------------------------
	public static double vectorInfinitive(int n, double[] vector) {
		double max = Math.abs(vector[1]);
		for (int i = 2; i < n + 1; i++)
			if (max < Math.abs(vector[i]))
				max = Math.abs(vector[i]);

		return max;
	}

	// ----------------------------------------------------------------------------------------
	// Compute the one-norm of a matrix.
	// ----------------------------------------------------------------------------------------
	public static double matrixOne(int n, double[][] matrix) {
		double[] sum = new double[n + 1];

		for (int i = 1; i < n + 1; i++)
			sum[i] = vectorOne(n, matrix[i]);

		double maxSum = sum[1];
		for (int i = 2; i < n + 1; i++)
			if (maxSum < sum[i])
				maxSum = sum[i];

		return maxSum;
	}

	// ----------------------------------------------------------------------------------------
	// Compute the Two-norm of a matrix.
	// ----------------------------------------------------------------------------------------
	public static double matrixTwo(int n, double[][] matrix) {
		return 0;
	}

	// ----------------------------------------------------------------------------------------
	// Compute the infinitive-norm of a matrix.
	// ----------------------------------------------------------------------------------------
	public static double matrixInfinitive(int n, double[][] matrix) {
		double[] sum = new double[n + 1];

		for (int j = 1; j < n + 1; j++)
			for (int i = 1; i < n + 1; i++)
				sum[j] += matrix[i][j];

		double maxSum = sum[1];
		for (int i = 2; i < n + 1; i++)
			if (maxSum < sum[i])
				maxSum = sum[i];

		return maxSum;
	}

}

⌨️ 快捷键说明

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