0

0

用Java编写的程序,用矩阵形式表示线性方程组

王林

王林

发布时间:2023-08-19 09:02:08

|

775人浏览过

|

来源于tutorialspoint

转载

用java编写的程序,用矩阵形式表示线性方程组

Java is an object oriented programming language which is used to solve and implement programs. In this segment of Java programming we are going to learn and discover about certain programs by which we can represent linear equations in Matrix form. To do these programs at first, we have to learn about linear equations and Matrix forms , their types and how they are solved by simple mathematical methods and then by Java programming.

In this article we will learn how to integrate a scanner class to take an input from the user by a java build code. Where the array will initialize to store some variables as an input for the problem matrix. Then it will converted into a loop by which the problem equation will be solved.

如何通过矩阵形式处理线性方程:

什么是线性方程?

Linear equation is a type of equation in which the highest power of a variable is 1 which is also known as a one-degree equation.

There are 3 major types of linear equations:-

立即学习Java免费学习笔记(深入)”;

  • 点斜式

  • Standard form

  • Slope intercept form

There are certain methods to solve linear equations like elimination method, substitution method, cross multiplication method and Matrix method.

在Java环境中,矩阵是什么?

矩阵是将给定的数字按行和列排列的方式。矩阵完全取决于给定集合中有多少行和列。这些可以包含不同的整数、变量,也可以是这些元素的组合形式,或者一些特殊的字母,如alpha、beta、gamma等。

There are so many types of matrix forms:-

  • row matrix

  • 列矩阵

  • null matrix

  • 方阵

  • diagonal matrix

    PHP经典实例(第二版)
    PHP经典实例(第二版)

    PHP经典实例(第2版)能够为您节省宝贵的Web开发时间。有了这些针对真实问题的解决方案放在手边,大多数编程难题都会迎刃而解。《PHP经典实例(第2版)》将PHP的特性与经典实例丛书的独特形式组合到一起,足以帮您成功地构建跨浏览器的Web应用程序。在这个修订版中,您可以更加方便地找到各种编程问题的解决方案,《PHP经典实例(第2版)》中内容涵盖了:表单处理;Session管理;数据库交互;使用We

    下载
  • upper triangular matrix

  • lower triangular matrix

  • 对称矩阵

  • 反对称矩阵

将线性方程表示为矩阵形式的算法:

  • 第一步 - 为编程生成一个扫描器类

  • Step 2 − take three different variables

  • 步骤3 - 逐一进行所有计算和形成

  • 第四步 - 打印所有变量和整数在S.O.P中

  • Step 5 − close the program with the scanner class system in the end and then compile the program.

Syntax

data_type[The Dimension][The Dimension].....[Nth number of dimension] 
array_name = new data_type[Size of data][size of data].......[size of data at Nth Position];

In the Java language this sequence of equations and Matrix sets up differently. We have to insert a program in which input will be given in linear equations and output will be in Matrix format or vice versa. To do these we have to go through many examples and steps in the following −

Approach

  • 方法一−为3个系数进行线性方程求解

Conduct the linear equations for the 3 coefficients:

例如,下面还展示了一个表示:

System of Linear Equation 3x + 5y + 8z = 24 8x + 10y + 12z = 30 2x + 4y + 5z = 5

Matrix representation

      3.   5.   8                  x                           24
 A =  8.  10.  12            X =   y                   B  =    30
      2.   4.   5.                 z                            5

For better understanding to represent the linear equations in Matrix form, we have provided a program to learn this set of coding below -

Example 1

import java.util.Scanner;

public class matrix07tutorialspoint {
	public static void main(String args[]){
      
      System.out.println("###### 3 variable linear equation ######");	
      char[] variable = { 'x', 'y', 'z' };
      Scanner sc = new Scanner(System.in);	
      System.out.println("Enter input as the coefficients of 3 variable");
      System.out.println("Enter in the specific format shown");
      System.out.println("ex + fy + gz = j");
      int[][] matrix = new int[3][3];
      int[][] constt = new int[3][1];

      
      for (int k = 0; k < 3; k++) {
      	
         for (int j = 0; j < 3; j++) {      
            matrix[k][j] = sc.nextInt();
      	 }	
      	 constt[k][0] = sc.nextInt();
      }
      System.out.println("Matrix representation of above linear equations is: ");
      for (int k = 0; k < 3; k++) {	
         for (int j = 0; j < 3; j++) {      
            System.out.print(" " + matrix[k][j]);
      	 }

      	 System.out.print(" " + variable[k]);
      	 System.out.print(" = " + constt[k][0]);
      	 System.out.println();
      }
      sc.close();
   }
}

输出

###### 3 variable linear equation ######
Enter input as the coefficients of 3 variable
Enter in the specific format shown
ex + fy + gz = j
Exception in thread "main" java.util.NoSuchElementException
	at java.base/java.util.Scanner.throwFor(Scanner.java:941)
	at java.base/java.util.Scanner.next(Scanner.java:1598)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2263)
	at java.base/java.util.Scanner.nextInt(Scanner.java:2217)
	at matrix07tutorialspoint.main(matrix07tutorialspoint.java:20)

Example 2

import java.util.Scanner;

public class ARBRDDTutorialpoint {
   public static void main(String args[]){
      System.out.println("====== n variable of a linear equation ======");
      
      char[] variable= { 'e', 'f', 'g', 'x', 'y', 'z', 'v' };
      System.out.println("Enter the number of variables");
      Scanner sc = new Scanner(System.in);
      int num = sc.nextInt();
      System.out.println("Enter the coefficients variable as we need to perform");
      System.out.println("To get the result enter the input in the format shown below");
      System.out.println("ex + fy + gz + ... = o");
	
      
      int[][] matrix = new int1[num][num];
      int[][] constt = new int1[num][1];
      for (int k = 0; k < num; k++) {
         for (int j = 0; j < num; j++) {
            matrix[k][j] = sc.nextInt();
      	 }
      	 constt[k][0] = sc.nextInt();
      }
      
      System.out.println("Matrix representation of above linear equations are: ");
      for (int i = 0; i < num; i++) {
         for (int j = 0; j < num; j++) {
            System.out.print(" " + matrix[i][j]);
      	 }
      	 System.out.print(" " + variable[i]);
      	 System.out.print(" = " + constt[i][0]);
      	 System.out.println();
      }
      sc.close();
	}
}

输出

====== n variable of a linear equation ======
Enter the number of variables
4
Enter the coefficients variable as we need to perform
To get the result enter the input in the format shown below
ex + fy + gz + ... = o
10 11 12 13
14 15 16 16
18 19 20 21
22 23 24 25

--------OUTPUT INCOMPLETE ------- PLEASE CHECK--------------

结论

Multidimensional arrays are used to store the input data in a row-column format. They can commonly use to store the 3D data.

From this article, we have learnt how to represent a linear equation in a matrix form and get problem solved input processed by the Java code.

相关文章

java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
java
java

Java是一个通用术语,用于表示Java软件及其组件,包括“Java运行时环境 (JRE)”、“Java虚拟机 (JVM)”以及“插件”。php中文网还为大家带了Java相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

832

2023.06.15

java正则表达式语法
java正则表达式语法

java正则表达式语法是一种模式匹配工具,它非常有用,可以在处理文本和字符串时快速地查找、替换、验证和提取特定的模式和数据。本专题提供java正则表达式语法的相关文章、下载和专题,供大家免费下载体验。

737

2023.07.05

java自学难吗
java自学难吗

Java自学并不难。Java语言相对于其他一些编程语言而言,有着较为简洁和易读的语法,本专题为大家提供java自学难吗相关的文章,大家可以免费体验。

734

2023.07.31

java配置jdk环境变量
java配置jdk环境变量

Java是一种广泛使用的高级编程语言,用于开发各种类型的应用程序。为了能够在计算机上正确运行和编译Java代码,需要正确配置Java Development Kit(JDK)环境变量。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

397

2023.08.01

java保留两位小数
java保留两位小数

Java是一种广泛应用于编程领域的高级编程语言。在Java中,保留两位小数是指在进行数值计算或输出时,限制小数部分只有两位有效数字,并将多余的位数进行四舍五入或截取。php中文网给大家带来了相关的教程以及文章,欢迎大家前来阅读学习。

398

2023.08.02

java基本数据类型
java基本数据类型

java基本数据类型有:1、byte;2、short;3、int;4、long;5、float;6、double;7、char;8、boolean。本专题为大家提供java基本数据类型的相关的文章、下载、课程内容,供大家免费下载体验。

446

2023.08.02

java有什么用
java有什么用

java可以开发应用程序、移动应用、Web应用、企业级应用、嵌入式系统等方面。本专题为大家提供java有什么用的相关的文章、下载、课程内容,供大家免费下载体验。

430

2023.08.02

java在线网站
java在线网站

Java在线网站是指提供Java编程学习、实践和交流平台的网络服务。近年来,随着Java语言在软件开发领域的广泛应用,越来越多的人对Java编程感兴趣,并希望能够通过在线网站来学习和提高自己的Java编程技能。php中文网给大家带来了相关的视频、教程以及文章,欢迎大家前来学习阅读和下载。

16925

2023.08.03

Java 桌面应用开发(JavaFX 实战)
Java 桌面应用开发(JavaFX 实战)

本专题系统讲解 Java 在桌面应用开发领域的实战应用,重点围绕 JavaFX 框架,涵盖界面布局、控件使用、事件处理、FXML、样式美化(CSS)、多线程与UI响应优化,以及桌面应用的打包与发布。通过完整示例项目,帮助学习者掌握 使用 Java 构建现代化、跨平台桌面应用程序的核心能力。

36

2026.01.14

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
NumPy 教程
NumPy 教程

共44课时 | 2.9万人学习

Django 教程
Django 教程

共28课时 | 3.1万人学习

Excel 教程
Excel 教程

共162课时 | 11.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号