83455

Solving linear eqn by efficient-java-matrix-library

Question:

I am using the following library for solving linear equation . The link of that library is as follows : <a href="http://code.google.com/p/efficient-java-matrix-library/wiki/EjmlManual" rel="nofollow">efficient-java-matrix-library</a>

I have downloaded the library file and imported in the eclipse . Then I have written the following code to solve a set of linear equations .

SimpleMatrix A1 = new SimpleMatrix(m,n); SimpleMatrix b1 = new SimpleMatrix(m,1); for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { A1.setRow(i, i, A2[i][j]); // System.out.println(); } b1.setColumn(i, 0, B2[i]); } try { SimpleMatrix x1 = A1.solve(b1); for(int i=0;i<x1.getNumElements();i++) { double value = x1.get(i, 0); System.out.println(" value of x"+i+" is "+value); } } catch ( SingularMatrixException e ) { // throw new IllegalArgument("Singular matrix"); }

But for this code I am having the following exception .

Exception in thread "main" java.lang.IllegalArgumentException: Specified element is out of bounds: (0 , 1) at org.ejml.data.DenseMatrix64F.set(Unknown Source) at org.ejml.simple.SimpleBase.setColumn(Unknown Source) at com.temp.temp.Main_function.main(Main_function.java:37)

I cant understand why I am getting this error . Can you please help me to solve this error ?

Answer1:

SimpleMatrix A1 = new SimpleMatrix(m,n); SimpleMatrix b1 = new SimpleMatrix(m,1);

for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { A1.setRow(i, j, A2[i][j]); double value1 = A1.get(i,j); System.out.print(" "+value1); // System.out.println(); } b1.setRow(i,0, B2[i]); double value2 = b1.get(i,0); System.out.print(" = "+value2); System.out.println(); } try { SimpleMatrix x1 = A1.solve(b1); for(int i=0;i<x1.getNumElements();i++) { double value = x1.get(i, 0); System.out.println(" value of x"+i+" is "+value); } } catch ( SingularMatrixException e ) { // throw new IllegalArgument("Singular matrix"); }

Recommend

  • Getting selected value of listbox windows phone 7
  • Wpf Grid, how to set Row , Column programarically
  • VB.NET and MySql UPDATE query
  • Dependencies in git
  • IF/AND Google Sheets error
  • How to use the result of previous row in oracle?
  • My Django manytomany fields are all marked unique, is there an option to remove this?
  • two interfaces, multiple inheritance combine into one container?
  • Combobox selected index is wrong
  • select only 1st level of nested elements
  • Matlab left - division in vectors?
  • Specify loader configuration from webpack config file in request
  • How to get intermediate colors from one to another? [duplicate]
  • Convert csv data to specific format DYNAMIC
  • Prolog - Balanced tree or not
  • Grid.GetRow and Grid.GetColumn keep returning 0
  • working with Nested IF statement in excel
  • Compare Dictionary
  • Omit template arguments when create an instance of template class from another instance of template
  • Check if one value in one column is in another column
  • Tips for creating scalable WPF user control
  • How to calculate total Fridays between two dates in excel on weekly, biweekly and monthly basis?
  • No error while instantiating abstract class, even though abstract method is not implemented
  • How to set `secure` and `httpOnly` for Plones `__ac` cookie?
  • Excel distinct count with conditions
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • several dataProvider per one Test in TestNG
  • How can we prepend rows to a react native list-view?
  • VBA Convert delimiter text file to Excel
  • ORA-29908: missing primary invocation for ancillary operator
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Sorting a 2D array using the second column C++
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal