This is java program to convert the system of linear equations to matrix form. The input is the coefficient of each variable and constant. Class rearranges them and converts them into matrix form, which aids solving them.
Here is the source code of the Java Program to Represent Linear Equations in Matrix Form. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
//This is a sample program to represent linear equations into matrix from import java.util.Scanner; public class Matrix_Representation_Equations { public static void main(String args[]) { char []var = {'x', 'y', 'z', 'w', 'a', 'b', 'c', 'd', 'e'}; System.out.println("Enter the number of variables in the equations: "); Scanner input = new Scanner(System.in); int n = input.nextInt(); System.out.println("Enter the coefficients of each variable for each equations"); System.out.println("ax + by + cz + ... = d"); int [][]mat = new int[n][n]; int [][]constants = new int[n][1]; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { mat[i][j] = input.nextInt(); } constants[i][0] = input.nextInt(); } System.out.println("Matrix representation is: "); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { System.out.print(" "+mat[i][j]); } System.out.print(" "+ var[i]); System.out.print(" = "+ constants[i][0]); System.out.println(); } input.close(); } }
Output:
$ javac Matrix_Representation_Equations.java $ java Matrix_Representation_Equations Enter the number of variables in the equations: 3 Enter the coefficients of each variable for each equations: ax + by + cz + ... = d 1 2 3 4 5 6 7 8 9 0 1 2 Matrix representation is: 1 2 3 x = 4 5 6 7 y = 8 9 0 1 z = 2
Related posts:
Set Interface trong Java
Spring Boot: Customize Whitelabel Error Page
Java Program to Perform Cryptography Using Transposition Technique
Java Program to Implement Weight Balanced Tree
Spring Security Form Login
Java Program to Find the Vertex Connectivity of a Graph
Java Program to do a Breadth First Search/Traversal on a graph non-recursively
Java Program to Implement Suffix Tree
Java Program to Perform Partition of an Integer in All Possible Ways
Java Program to Implement Graham Scan Algorithm to Find the Convex Hull
Stack Memory and Heap Space in Java
Collection trong java
Java Program to Implement the Bin Packing Algorithm
Java Program to Implement D-ary-Heap
Map Serialization and Deserialization with Jackson
Java Program to Perform Sorting Using B-Tree
Java – Get Random Item/Element From a List
Logging in Spring Boot
Using JWT with Spring Security OAuth (legacy stack)
Concurrent Test Execution in Spring 5
Java Program to Implement Min Heap
Java Collections Interview Questions
MyBatis with Spring
Java Program to Find a Good Feedback Vertex Set
Guide to System.gc()
Java Program to Implement Horner Algorithm
Spring Boot Annotations
String Operations with Java Streams
Java Program to Describe the Representation of Graph using Adjacency List
Examine the internal DNS cache
Spring Boot Application as a Service
How to Count Duplicate Elements in Arraylist