{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PGE 310 - HW 4 - Solution

PGE 310 - HW 4 - Solution - The University of Texas at...

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

View Full Document Right Arrow Icon
The University of Texas at Austin Fall 2011 - PGE 310: Formulation and Solution in Geosystems Engineering Homework #4: If Statements and Loop Structures By Hossein Roodi 1. Summation and Product Using Loops (By HAND) Consider the following vector, x , and matrices, A and B : ] 2 8 6 1 2 3 2 5 5 3 4 2 3 1 [ x 2 4 1 2 1 4 1 2 4 A 1 4 1 2 1 2 1 1 2 B Calculate the following by hand and then write (by hand) the equivalent MATLAB loop a. 10 5 2 ) 1 ( i i i 737 . 39 091 . 9 1 . 8 111 . 7 125 . 6 143 . 5 167 . 4 ) 1 10 10 ( ) 1 9 9 ( ) 1 8 8 ( ) 1 7 7 ( ) 1 6 6 ( ) 1 5 5 ( 2 2 2 2 2 2 hand by % Part a suma = 0; for i = 5 : 10 suma = suma + (i ^2) / (i+1); end b.   3 1 3 1 2 3 ) ) ( ( ij j ji i B A A    4 ) 0 2 ( ) 3 2 ( ) 2 1 ( ) 2 2 ( ) 1 2 ( ) 2 1 ( 2 ) 2 4 ( ) 1 1 ( ) 2 2 ( 2 ) 2 1 ( ) 1 4 ( ) 2 4 ( 1 ) 3 , 2 ( ) 3 , 3 ( ) 2 , 2 ( ) 3 , 2 ( ) 1 , 2 ( ) 3 , 1 ( ) 3 , 3 ( ) 3 1 , 3 ( ) 3 , 2 ( ) 2 , 3 ( ) 2 , 2 ( ) 2 , 2 ( ) 1 , 2 ( ) 2 , 1 ( ) 3 , 2 ( ) 3 1 , 2 ( ) 3 , 2 ( ) 1 , 3 ( ) 2 , 2 ( ) 1 , 2 ( ) 1 , 2 ( ) 1 , 1 ( ) 3 , 1 ( ) 3 1 , 1 ( B A B A B A A to j i B A B A B A A to j i B A B A B A A to j i hand by % Part b A = [ 4 2 -1; -4 1 -2; 1 4 -2 ], B = [ -2 -1 1; -2 -1 2; -1 4 1], sumb = 0; for i = 1 : 3 sumb2 = 0; for j = 1 : 3 sumb2 = sumb2 + A(j,i)*B(2,j); end sumb = sumb + A(i,3) * sumb2 ; end
Background image of page 1

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

View Full Document Right Arrow Icon
c. 3 1 1 ) ( i ii i B x 48 ) 1 4 ( ) 1 2 ( ) 2 3 ( ) ) 3 , 3 ( ( ) ) 2 , 2 ( ( ) ) 1 , 1 ( ( 4 3 2 B x B x B x hand by % Part c x = [ -1 3 -2 4 -3 5 -5 2 -3 -2 1 6 -8 2 ] prodc = 1; for i = 1 : 3 prodc = prodc * x(i+1) * B(i,i); end d. 3 1 3 1 ) ( j j i ij x A j    512 6 3 16 16 ) 2 2 2 1 3 ( ) 3 4 1 2 2 ( ) 1 1 4 4 1 ( ) 3 , 3 ( ) 3 , 2 ( ) 3 , 1 ( 3 ) 3 1 , 3 ( ) 2 , 3 ( ) 2 , 2 ( ) 2 , 1 ( 2 ) 3 1 , 2 ( ) 1 , 3 ( ) 1 , 2 ( ) 1 , 1 ( 1 ) 3 1 , 1 ( 3 2 1 x A A A to j i x A A A to j i x A A A to j i hand by % Part d prodd = 1; for j = 1 : 3 prodd2 = 1; for i = 1 : 3 prodd2 = prodd2 * A(i,j); end prodd = prodd * j * prodd2 / x(j) end e. 16 15 .... 6 5 4 3 2 1 2 2 2 683 . 7 063 . 14 071 . 12 083 . 10 1 . 8 125 . 6 167 . 4 25 . 2 5 . 0 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 2 2 2 2 2 2 2 hand by 15 ,... 5 , 3 , 1 2 2 ) 1 ( 2 2 2 2 2 2 2 1 ) 1 ( 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 i i i i ng programmi for or % Part e sume = 0; for i = 1:2:15 sume = sume + (i ^2) / (i+1) * (-1)^ ((i+1)/2) end (30 %)
Background image of page 2
2. Loop Structure (By HAND) Consider the following MATLAB code written in a script file segment and determine the value of “ ires ” and/or “ jres ” at the end of each of the loops, and also the number of times each loop executes. Clearly show your intermediate calculation steps for each time the loops execute.
Background image of page 3

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

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

{[ snackBarMessage ]}

Page1 / 10

PGE 310 - HW 4 - Solution - The University of Texas at...

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

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