Solved

matrix handling function

Posted on 1997-12-05
6
280 Views
Last Modified: 2010-04-02
how to determine the transpose and inverse of a matrix A and Matrix B using C language
0
Comment
Question by:latino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:latino
ID: 1256518
ASAP
0
 
LVL 10

Expert Comment

by:rbr
ID: 1256519
It depends on the dimension of the matrix, because there exists
different algorithm. If you are interessted in such codes use
the book Numerical Recipes for C.
0
 

Author Comment

by:latino
ID: 1256520
I need some help about this online so if any info let me know
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:rbr
ID: 1256521
Pls tell my what is the dimension of the matrix, is it a sparse matrix, ... This information is needed to determine which algorithm you should use.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1256522
0
 

Accepted Solution

by:
hbadr earned 100 total points
ID: 1256523
latino

to do this you Dynamically allocate and then perform whatever operation you need using the operator [].
the example below transpotse a matrix of n,m dimention.

#include <conio.h>
#include <Stdio.h>
#include <alloc.h>

void getinput ( int **ArrayPtr , int raws , int cols );
int **transpose( int **ArrayPtr , int raws , int cols );
void display( int **ArrayPtr ,int raws ,int cols );

void main()
{
 int **ArrayIn;
 int raws,cols;
 int i,j;

 clrscr();

 printf("Enter Number Of Raws : ");       //Get Array Dimentions
 scanf("%d", &raws );
 printf("Enter Number Of Columns : ");
 scanf("%d", &cols );

 ArrayIn = calloc ( raws , sizeof(int *) );     //Dynamically Allocate The Array
 for ( j=0 ; j<raws ;j++ ){
     ArrayIn[j] = calloc( cols, sizeof(int) );
 }

 getinput( ArrayIn ,raws ,cols );      // Get the Array

 ArrayIn=transpose(ArrayIn ,raws,cols);            //Transpose the Array

 display(ArrayIn , raws , cols);          // Display After Transpose

 getch();

}

////////////////////////////////////
void getinput ( int **ArrayPtr , int raws , int cols ){
int i,j;

 for( j=0 ; j<raws ;j++ ){
     for( i=0 ; i<cols ; i++ ){
       printf("Enter Element #%d%d : ",j,i);
       scanf("%d",ArrayPtr[j]+i);
     }
 }
}
//////////////////////////////////////////////
int **transpose( int **ArrayPtr , int raws , int cols ){
 int **trans;
 int i,j;

 trans = calloc ( cols , sizeof(int *) ); // Allocate Transpose Array
 for ( j=0 ; j<cols ;j++ ){
     trans[j] = calloc( raws, sizeof(int) );
 }


 for( j=0 ; j<raws ;j++ ){
 printf("\n");
     for( i=0 ; i<cols ; i++ ){
      trans[i][j]=ArrayPtr[j][i];
     }

 }
 return (trans);

}
////////////////////////////
void display( int **ArrayPtr ,int raws , int cols ){
 int i,j;

 for( j=0 ; j<cols ;j++ ){
     printf("\n");
     for( i=0 ; i<raws ; i++ ){
       printf("#%d%d = %d  |",j,i,ArrayPtr[j][i]);
     }
 }
}

//////////

likewise you could do any operation you need by using a similar algorithm.

E-mail me at : hbadr@mailcity.com

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question