It looks like you're new here. If you want to get involved, click one of these buttons!

- 141.1K All Categories
- 103.8K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 551 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.9K Visual Basic
- 2.6K Game programming
- 317 Console programming
- 93 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 745 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 258 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 199 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 604 Jobs Wanted
- 211 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 355 Comments on this site
- 70 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 637 Off topic board
- 220 Mobile & Wireless
- 92 Android
- 126 Palm Pilot
- 340 Multimedia
- 156 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 371 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 943 Software Development
- 417 Algorithms
- 68 Object Orientation
- 92 Project Management
- 95 Quality & Testing
- 270 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 62 AJAX
- 6 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 309 WEB Servers
- 155 WEB-Services / SOAP

dynamic_cd
Member Posts: **1**

in Java

Hi everyon,

This is CD. I am writing a project which determines the values of Xs (X1, X2, X3..., Xn) using the guassian elimination (Linear Algrebra). The equation is written in a text file. For example, Equation.txt includes the following equations:

I just made up these numbers.

2

3 -3 6

-1 4 9

3

3 4 5 6

7 8 9 10

11 12 13 14

If you take a look at Equation 1, the linear equation should be written as:

2 (the number of equations)

3 -3 6 --> 3X1 - 3X2 = 6

-1 4 9 --> -X1 + 4X2 = 9

Same thing with Equation 2, but there are 3 equations.

3 (the number of equations)

3X1 + 4X2 + 5X3 = 6

7X1 + 8X2 + 9X3 = 10

11X1 + 12X2 + 13X3 = 14

How can store these numbers, which are read from the Equation.txt, in a 2-dimensional array?

If you know the answer to this question, please help.

Thanks for your time and consideration.

CD

This is CD. I am writing a project which determines the values of Xs (X1, X2, X3..., Xn) using the guassian elimination (Linear Algrebra). The equation is written in a text file. For example, Equation.txt includes the following equations:

I just made up these numbers.

2

3 -3 6

-1 4 9

3

3 4 5 6

7 8 9 10

11 12 13 14

If you take a look at Equation 1, the linear equation should be written as:

2 (the number of equations)

3 -3 6 --> 3X1 - 3X2 = 6

-1 4 9 --> -X1 + 4X2 = 9

Same thing with Equation 2, but there are 3 equations.

3 (the number of equations)

3X1 + 4X2 + 5X3 = 6

7X1 + 8X2 + 9X3 = 10

11X1 + 12X2 + 13X3 = 14

How can store these numbers, which are read from the Equation.txt, in a 2-dimensional array?

If you know the answer to this question, please help.

Thanks for your time and consideration.

CD

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2017 Programmersheaven.com - All rights reserved.

## Comments

272int[][] = new int[n][n+1];

Then when you read in the next line, you store the numbers in the appropriate slot in the array. What you have to be careful about is parsing the string correctly, but I am assuming you have a method for that. As well, if you are trying to initialize a large matrix, say, 200 equations, then it would be tedious to do that within your main method. You should have a method for initializing the provided row of the matrix (determined by the first dimension of the array) with the values found in the provided string, knowing that there are n variables (determined by the size of the second dimension of the array). Your program would then read in the file line by line, pass each line to the method in a loop, and when the end of the file is reached, then you have initialized the entire matrix.

The problem that you might later encounter is that some systems of equations don't have unique solutions, which is what happens when two of your equations are multiples of each other, or you have a row of 0's. If there are fewer equations than variables, your program should be capable of realizing that, and should initialize the last row(s) of the matrix with 0's. This will help later when it comes to solving the matrix when you can place all the rows containing 0's at the end, and when you have reduced to that point, you are finished, and have to create temporary variables for each unreduced unknown. (If you can't solve for X4, then let X4 = t, and then state the solutions for X1, X2, X3 in terms of a constant and t. If you have more than one unsolved variable, then create another temp variable for each unknown, so that a solution for X1 might look like X1 = 5 - 3t + 2s.)

If you need more help with this, just ask. I just finished a course in this subject (linear algebra) and have made segments of a program to solve (n, n+1) matrices, so I should be able to give you a few pointers that will save your program large amounts of time.

If you have enough memory, you won't have enough disk space.

0✭____ \ http://forcoder.org \ free ebooks and video tutorials about ( JavaScript, Scratch, Objective-C, Swift, Visual Basic, Ruby, PHP, C++, Assembly, Java, MATLAB, Perl, Go, R, C, PL/SQL, Visual Basic .NET, Delphi, Python, C# Kotlin, ML, Prolog, Logo, LabVIEW, Rust, Scala, Julia, COBOL, Awk, SAS, VBScript, Lisp, Scheme, Fortran, Erlang, Lua, Alice, Apex, F#, Ada, Hack, Bash, Transact-SQL, D, Dart, Clojure, Crystal, FoxPro, ABAP )