Solved

matrix handling function

Posted on 1997-12-05
6
281 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
Industry Leaders: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

623 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