Discussion Notes 10

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

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

View Full Document Right Arrow Icon
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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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; }
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online