Results 1 to 6 of 6

Thread: Operations on matrices

  1. #1
    Join Date
    Dec 2009
    Posts
    213

    Operations on matrices

    Hello,
    I am beginner in java, I wanted to make a program that performs basic operations on square matrices sum, product numbers, display. I do this bit of code but that does not give the desired result. I have done some part of the code, but I do not think that is correct. So, if you have any idea about it then please do post back and it you have an sample example then it would be great.

  2. #2
    Join Date
    Apr 2008
    Posts
    264

    Re: Operations on matrices

    Hello,
    I have done some work on this before and I have a code with me , but even I am not sure that this works perfectly.
    Code:
    Public class Matrix{
     
    private int[][] m;
    
    Public void Matrix(int[][] m){
     this.m = m;
    }
     
    private static int [][] multiplies(int m[ ][ ],int number)
    {
    int t [][] = new int[m.length][m.length];
     for(int i =0; I <m.length; I + +){
     for(int j =0J <m.lengthJ + +)
     t [i][j] * M = number[i][j];
    }
     return t;
     }
     
    Public static int [] [] sum(int m1[] [],int m2[] []){
    int m[] [] = new int[2][2];
    	for(int i =0; i <2; i + +)
    	for(int j =0j <2j + +)
    	{
    	m[i][j]= m1[i][j]+ m2[i][j];
    	}
    return m;
    }
     
    Public static void display( int[][] t){ 
    for (int i = 0 ; I <t.length , I = i + 1 ) 
    for (int j = 0 J <t.length J + + ) 
    System.out.System.out.println(t[i][j]) ;
        }
    }

  3. #3
    Join Date
    Nov 2009
    Posts
    356

    Re: Operations on matrices

    Hello,
    I would have rather done this
    Code:
    Public static void display( int[][] x){ 
      for (int i = 0 ; I <x.length , I = i + 1 ) 
        for (int j = 0 J <x.length J + + ){ 
          System.out.print(x[i][j] + " ") ;
        }
        System.out.System.out.println("");
      }
    }
    Otherwise the rest not too bad, apart from that you might matrices are not square.

  4. #4
    Join Date
    Nov 2009
    Posts
    333

    Re: Operations on matrices

    Hello,
    I have tested this part of the code and I think this code works perfectly.
    Code:
    Public static void hand(String [] args){
    int m1[] [] = {{3,4},{5,6}};
     
    int m2[] [] = {{7,7},{7,7}};
    display(m1);
    multiplies(m1,3);
    display(m1);
    System.out.System.out.println(sum(m1, m2));
    System.out.System.out.println(Product(m1, m2));
    }
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Operations on matrices

    Hello,
    The result is quite consistent with your code
    Alternatively you can try this code
    Code:
    Public static void hand(String [] args){
    int m1[] [] = {{3,4},{5,6}};   
    int m2[] [] = {{7,7},{7,7}};
    display(m1);
    display(multiplies(m1,3));
    display(sum(m1, m2));
    display(Product(m1, m2)); 
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: Operations on matrices

    Hello,
    You can even try the following logic in your code
    Code:
    Public static void display( int[][] x){ 
      for (int i = 0 ; I <x.length , I = i + 1 ) 
        System.out.print("( ");
        for (int j = 0 J <x.length J + + ){ 
          System.out.print(x[i][j] + " ") ;
        }
        System.out.System.out.println(")");
      }
    }
    Or something like think this would be great.

Similar Threads

  1. Operations management
    By RAJni-Gandha in forum Education Career and Job Discussions
    Replies: 4
    Last Post: 18-11-2010, 04:56 PM
  2. Details about operations management project
    By denny walter in forum Education Career and Job Discussions
    Replies: 3
    Last Post: 18-11-2010, 03:15 AM
  3. Replies: 6
    Last Post: 08-10-2010, 11:57 PM
  4. Path Operations and File Operations in Java
    By super soaker in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 01:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,012,319.35829 seconds with 16 queries