1

I am using Universal Java Matrix Package to creating Matrix,Sparse Matrix,Identity Matrix and Matrix operation like addition,subtraction,transpose etc. I have some problem to implementing a code.

  1. How to create identity Matrix using UJMP?

    Here is my code

    import org.ujmp.core.Matrix;

    import java.io.File;
    
    import java.io.IOException;
    
    import java.util.Scanner;
    
    public class odou {
    
    public static void main(String args[])throws IOException {
    
    double t = 0.002;
    
        double time=0.0,forwardvelocity=0.0,angularvelocity=0.0;
        Matrix Gt=Matrix.Factory.zeros(3,3);
    
    
        Scanner x=new Scanner(new File("/home/froboticscse/IdeaProjects/UJMPtest/src/main/java/Robot1_O.txt"));
        while(x.hasNext()) {
            time = x.nextDouble();
            forwardvelocity = x.nextDouble();
            angularvelocity = x.nextDouble();
    
            Gt.setAsDouble(1.0,0,0);
            Gt.setAsDouble(0.0,0,1);
            Gt.setAsDouble((-forwardvelocity*t*Math.sin(theta_initialU+(angularvelocity*t)/2)),0,2);
            Gt.setAsDouble(0.0,1,0);
            Gt.setAsDouble(1.0,1,1);
            Gt.setAsDouble((forwardvelocity*t*Math.cos(theta_initialU+(angularvelocity*t)/2)),1,2);
            Gt.setAsDouble(0.0,2,0);
            Gt.setAsDouble(0.0,2,1);
            Gt.setAsDouble(1.0,2,2);
        } }}
    

    I have a file name Robot1_O.txt which consist of 3 column and various row. I am using Scanner class to scan this value. This value is loop within Gt matrix. Gt is a 3*3 matrix. I also wanted to create a 3*3 identity matrix.

    After creating this identity matrix I create another matrix say New which is like (I -Gt). I cannot find any documentation about how to create identity matrix using UJMP.

    If any one know that please share it.

Victor Gubin
  • 2,782
  • 10
  • 24
Encipher
  • 1,370
  • 1
  • 14
  • 31

2 Answers2

2

Try the following

Matrix identity = DenseMatrix.Factory.zeros(3, 3);
for(int i=0; i < 3; y++)
   identity.setAsDouble(1.0, i, i);
Victor Gubin
  • 2,782
  • 10
  • 24
2

There is no build in identity matrix in UJMP matrix package like JAMA matrix package. If you don't need sparse or dense matrix operation,only need some basic matrix operations it is better to use JAMA matrix. JAMA have a proper documentation.

Geek
  • 395
  • 1
  • 9