ME581_Assignment01-Sol

ME581_Assignment01-Sol - ME 581 Assignment #1 - Solution In...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ME 581 Assignment #1 - Solution In the following questions show the derivations that you used to write your program. 1. Write a subroutine to do matrix multiplication [ C ] = [ A ] [ B ] of arbitrary sized matrices. The input to the program should be: The first matrix [ A ], the number of rows of [ A ] and the number of columns of [ A ]. The second matrix [ B ], the number of columns of [ B ] (The number of rows of [ B ] is equal to the number of columns of [ A ]). The output of the subroutine is matrix [ C ]. Test your program using the following matrices: = 1 1 4 2 4 1 0 1 2 3 5 9 1 0 2 2 1 0 3 2 ] [ A = 4 1 1 3 4 3 2 1 0 4 1 0 2 1 2 ] [ B Matrix multiplication: kj ik ij B A C = #define s1(i,j,Mclns) ((i)*(Mclns)+j) void MatrixMultiply( double *A, int n, int m, double *B, int mb, double *C) { int i, j, k, kk; for (i=0;i<n;i++){ for (j=0;j<mb;j++){ kk=s1(i,j,mb); C[kk]=0.; for (k=0;k<m;k++)C[kk]+=A[s1(i,k,m)]*B[s1(k,j,mb)]; } } } = = 9 11 6 4 5 7 5 44 18 19 7 1 ] ][ [ ] [ B A C
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. Write a subroutine to do the multiplication C j = A ijk B ik of arbitrary sized multi-dimensional matrices. The input to the program should be: a. The multidimensional matrix [ A ], the maximum value of the indices of i , j and k . b. The second matrix [ B ]. The output of the subroutine is vector { C }. Test your program using the following matrices: = 2 2 2 1 1 1 ] [ 1 jk A = 2 1 2 1 2 1 ] [ 2 jk A = 1 1 1 2 1 2 ] [ 3 jk A = 2 1 1 1 1 2 ] [ 4 jk A = 3 4 3 2 1 0 4 1 0 2 1 2 ] [ B #define s3(i,j,k,jN,kN) ((i)*(jN*kN)+(j)*(kN)+k) #define s1(i,j,Mclns) ((i)*(Mclns)+j) double A1[4*2*3]={1.,1.,-1, 2.,2.,2., -1.,2.,1., -2.,1.,2., 2.,-1.,-2., 1.,-1.,1., -2.,-1.,1., 1.,1.,-2.}; double B1[4*3]={2.,-1., 2., 0., 1., 4., 0.,-1.,-2., 3., 4., 3.}; void MultiplyAijk_Bik( double *A, double *B, int iN, int jN, int kN, double *C) { int i, j, k; for (j=0;j<jN;j++)C[j]=0.; for (i=0;i<iN;i++){ for (j=0;j<jN;j++){ for (k=0;k<kN;k++){ C[j]+= A[s3(i,j,k,jN,kN)]* B[s1(i,k,kN)]; } } } } = 15 3 ] [ C
Background image of page 2
3. Write a recursive subroutine to calculate the determinant of a matrix. The input to your subroutine should be matrix [ A ] along with its number of rows and columns. The output to the subroutine should be the value of determinant. Test your program using the following matrix.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/16/2011 for the course MECHANICAL 581 taught by Professor Wasfy during the Fall '11 term at IUPUI.

Page1 / 7

ME581_Assignment01-Sol - ME 581 Assignment #1 - Solution In...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online