首页 > 编程源码 > 高数 矩阵的基本运算

高数 矩阵的基本运算

楼主:安然 [3级] · 2019-11-13 ·  浏览612 · 编程源码 · ID:

一、介绍1、介绍。 矩阵的运算,本质上就是二维数组的运算。2、公共代码。/** * 打印二维数组 * * @param a 二维数组a */public static void print(double[][] a) { print(a, 5, 0);} /** * 打印二维数组 * * @param a 二维数组a * @param precision 如果是浮点型的话,保留几位小数 */public static void print(int[][] a, int width, int precision) { String str = "%" + width + "d "; for (int i = 0; i < a.length; i++) { int[] aItem = a[i]; for (int j = 0; j < aItem.length; j++) { System.out.print(String.format(str, aItem[j])); } System.out.println(); }} /** * 打印二维数组 * * @param a 二维数组a * @param precision 如果是浮点型的话,保留几位小数 */public static void print(double[][] a, int width, int precision) { String str = "%" + width + "." + precision + "f "; for (int i = 0; i < a.length; i++) { double[] aItem = a[i]; for (int j = 0; j < aItem.length; j++) { System.out.print(String.format(str, aItem[j])); } System.out.println(); }}二、减法。1、介绍。 \LARGE \begin{bmatrix}a&b\\ c&d\end{bmatrix} - \begin{bmatrix}e&f\\ g&h\end{bmatrix} = \begin{bmatrix}a-e&b-f\\ c-g&d-h\end{bmatrix}2、代码。/** * 矩阵a和b对应位置的数相减 * * @param a 矩阵a[m][n] * @param b 矩阵b[n][p] */public static double[][] sub(double[][] a, double[][] b) throws Exception { int row = a.length; int column = a[0].length; int bRow = b.length; int bColumn = b[0].length; if (row != bRow || column != bColumn) { throw new Exception("两个矩阵的大小不一致"); } double[][] result = new double[row][column]; for (int i = 0; i < row; i++) for (int j = 0; j < column; j++) result[i][j] = a[i][j] - b[i][j]; return result;}public static void main(String[] args) { try { double[][] a = new double[][]{ {1, 2, 3, 4}, {5, 6, 7, 8}, {1, 1, 2, 2}, {3, 3, 4, 4}, }; System.out.println("矩阵a:"); ArrayUtils.print(a); do

- 版权声明 - 1、本帖所有言论和图片等纯属网友个人意见,与流星社区立场无关;
2、其他单位或个人使用、转载或引用本帖时必须同时征得该帖子作者安然流星社区的同意;
3、备注原文地址:https://bbs.liuxingw.com/t/17142.html,可忽略第2条;
4、帖子作者需承担一切因本文发表而直接或间接导致的相关责任;
5、如本帖内容或部分内容转载自其它媒体,这并不代表本站赞同其观点和对其真实性负责;
6、如本帖若为资源类,将仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您安装或使用的设备中彻底删除上述内容;
7、如果您喜欢该程序,请支持正版软件,购买注册,可以得到更好的正版服务;
8、如本帖侵犯到任何版权或违法问题,请立即邮件告知我们,我们将及时予以处理。
1条回复 |  最后回复于2019-11-13

囚墨[蜷] [1级]

恢复一下.
发布于2019-11-13

回复列表

  • 内容加载中...

说点什么...
登录注册 后才可进行评论
签到
39人签到
已签0天
  • 46637帖子
  • 1936935热点量
  • 185040火热值