Discussion Notes 10

# Discussion Notes 10 - EME 5 Fall 2007 Discussion 10 Example...

This preview shows pages 1–3. Sign up to view the full content.

EME 5 Fall 2007 Discussion 10 Example 1: Given = = = 2 1 , 2 1 4 3 , 4 3 2 1 b B A Calculate x = 2 ABb + Ab using computational arrays and print out x . /* ex1.ch */ #include <stdio.h> #include <array.h> int main() { array int A[2][2] = {1, 2, 3, 4}, B[2][2] = {3, 4, 1, 2}, b[2][1] = {1, 2}, x[2][1]; x = 2*A*B*b + A*b; printf("x =\n%d\n", x); return 0; }

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

View Full Document
Example 2: Write a program having a function that performs the following matrix calculation and returns the resultant matrix. f( A , B , c) = A .* B + c B Matrices A and B , and constant c are arguments of the function, where 2 , 3 2 1 6 5 4 , 6 5 4 3 2 1 = = = c B A /* ex2.ch */ #include <stdio.h> #include <array.h> array int f(array int A2[2][3], array int B2[2][3], int c2)[2][3] { return (A2.*B2 + c2*B2); } int main() { array int A[2][3] = {1, 2, 3, 4, 5, 6}, B[2][3] = {4, 5, 6, 1, 2, 3}, x[2][3]; int c = 2; x = f(A, B, c); printf("x =\n%d\n", x); return 0; }
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/21/2008 for the course EME 005 taught by Professor Cheng during the Fall '07 term at UC Davis.

### Page1 / 10

Discussion Notes 10 - EME 5 Fall 2007 Discussion 10 Example...

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

View Full Document
Ask a homework question - tutors are online