3.
9 Problems                                                                                              87
                                                (x+
      3.   For the function y =
                                            (x+ 1) x
                                                      7j   , calculate the value of y for the following
           values of x using element-by-element operations: 1.5, 2.5, 3.5, 4.5, 5.5, 6.6 .
                               ·            2 sinx+  cos2x                                          .
      4.   For the funct10n y =                   .        , calculate the value of y for the followmg
                                                   2
                                                 sm x
           values ofxusing element-by-element operations: 20°, 30°, 40°, 50°, 60°, 70°.
      5.   The radius, r, of a sphere can be calculated from its surface area, s, by:
                                                              --
                                                                Ji1ic
                                                           r=  2
           The volume, V, is given by:
                                                                 41tr3
                                                           V=    -
                                                                   3
           Determine the volume of spheres with surface area of 50, 100, 150, 200, 250,
           and 300    tt2.     Display the results in a two-column table where the values of s
           and V are displayed in the first and second columns, respectively.
      6.   The electric field intensity, E(z), due to a ring                          z
           of radius R at any point z along the axis of the
           ring is given by:
                                     -    ')...  Rz
                              E(z)
                                         2Eo(z2 + R2)312
           where       J...        is     the     charge        density,
           e0 = 8.85 x         I0-12 is the electric constant, and
           R is the radius of the ring. Consider the case
           where J... = 1.7 x to-7 C/m and R = 6 em.
           (a)   Determine E(z) at z = 0, 2, 4, 6, 8, and 10 em.
           (b) Determine the distance z where E is maximum. Do it by creating a vector
                 z with elements ranging from 2 em to 6 em and spacing of 0.01 em. Cal
                 culate E for each value of z and then fmd the maximum E and associated z
                 with MATLAB's built-in function max.
      7.   The voltage Vc(t)              (in V) and the current i(t)
           (in Amp) t seconds after closing the switch in
           the circuit shown are given by:
                              Vc(t) = V0(1- e-tl�o         )
                                            v.
                                     i(t) = _Qe-tl'to
                                             R
           where 'to = RC is the time constant. Consider the case where V0 = 24 V,
           R = 3800 Q and C = 4000 x I0-6 F. Determine the voltage and the current
           during the first 20 s after the switch is closed. Create a vector with values of
88                                                    Chapter 3: Mathematical Operations with Arrays
          times from 0 to20 s with spacing of2 s, and use it for calculating Vc(t) and
          i(t). Display the results in a three-column table where the values of time,
          voltage and current are displayed in the first, second, and third columns,
          respectively.
     8.   The length lui           (magnitude) of a vector u               =   xi+yj+zk is given by
          u
          l i   =       Jx2+y2+z2. Given the vector u              =   23.5i- 17j+ 6k, determine its
          length in the following two ways:
          (a)       Define the vector in MATLAB, and then write a mathematical expression
                    that uses the components of the vector.
          (b)       Define the vector in MATLAB, then determine the length by writing one
                    command that uses element-by-element operation and MATLAB built-in
                    functions   sum and sqrt.
     9.   A vector wL of length Lin the direction of a vector u                 =   xi+yj+zk can deter
          mined by          wL = Lun        (multiplying a unit vector in the direction ofu by L ).
          The unit vector un                 in the direction of the vector u              is   given by
                        xi+yj+zk             . .                                .
          un        =                                ll..rA'TLAB command, determme a vector
                                      . By wntmg one 1v.lr\.
                        Jx2+y2+z2
          of length 1 8 in the direction of the vector u           =   7i- 4j- 11k .
     1 0. The following two vectors are defmed in MATLAB:
                                       v =   [15,8,-6]     u   =   [3,-2,6]
          By hand (pencil and paper) write what will be displayed if the following com
          mands are executed by MATLAB. Check your answers by executing the com
          mands with MATLAB.
          (a) v. /u                          (b) u' *v                     (c) u*v'
     11. Two vectors are given:
          u     =   5i- 6j+9k and            v =   11i+7j- 4k
          Use MATLAB to calculate the dot product u ·                  v   of the vectors in three ways:
          (a)       Write an expression using element-by-element calculation and the MAT-
                LAB built-in function          sum.
          (b)       Define u as a row vector and vas a column vector, and then use matrix
                    multiplication.
          (c)       Use the MATLAB built-in function           dot.
     12. Defme the vector             v =   [2 3 4 5 6]. Then use the vector in a mathematical
          expression to create the following vectors:
          (a)       a = [4 6 8 10 12]                    (b) b = [8 27 64 125 216]
          (c)       c = [22 33 44 5s 66]                 (d) d = [1 1.5 2 2.5 3]
3.9 Problems                                                                                                                                   89
      13. Define the vector                v =     [8    6 4 2]      . Then use the vector in a mathematical
          expression to create the following vectors:
          (a)    a =     [1 1 1 1]                                   (b)     b =
                                                                                      [   1       1     1        1   ]
                                                                                          82 62 42 22
          (c)    c =
                         [J8 J6 J4 J2]
                          1   1        1       1
                                                                     (d)     d = [3 1             -1         -3 ]
      14. Define x andy as the vectors                    x=    [1, 2, 3, 4,     5]       and         y=        [2,   4, 6, 8,     10]. Then
          use them in the following expressions to calculate z using element-by-element
          calculations.
          (a)    z   =
                         (x +y)2
                          x-y
                                                                     (b)     w   = xln(x2 + y2) +                     J(y-x)2 Y3
      15. Define r and s as scalars r = 1 .6 x 103 and                            s   =       14. 2 , and,            t, x,   andy as vec
          tors    t= [1, 2, 3, 4, 5]       ,   x=       [0, 2, 4,   6, 8],   and      y=          [3,   6, 9, 12,          15] . Then use
          these variables to calculate the following expressions using element-by-ele
          ment calculations for the vectors.
          (a)    G =
                              r
                         xt+ -(y2-x)t
                             s2
                                                                     (b)     R =
                                                                                      r
                                                                                       (-     x�;ytz -s2(y-0.5x2)t
                                                                                                             )
      16. The area of a triangle ABC can be calculated by                                                   z
                                                                                                                         c (-5, 2,11)
          lrAB x rAd/2, where rAB and rAe are vectors
                                                                                                                               -
          connecting the vertices A and B and A and C,
          respectively. Determine the area of the triangle
          shown in the figure. Use the following steps in
          a script file to calculate the area. First, defme                                   x
          the vectors r oA, rOB and rae from knowing                                                                                y
                                                                                                            A (8, 5,-4)
          the coordinates of points A, B, and C. Then
          determine the vectors r AB and rAe from r oA, rOB and rae. Finally, determine
          the area by using MATLAB's built-in functions cross, sum. and sqrt.
      17. The volume of the parallelepiped shown can be
          calculated by r0B (r0A x rAe). Use the follow
                                   ·
          ing steps in a script file to calculate the area.
          Defme the vectors r oA , rAe, and rOB                                  from
          knowing position of points A, B, and C.
          Determine the volume by using MATLAB 's
          built-in functions dot and cross.
90                                                                 Chapter3: M&thematicalOperationswidlArrays
     18. Define the vectors:
                          u    =   Sl-2j +4k, v              =   -21+ 7J +3k, and w                  =    81 + lj -3k
         Use the vectors to verify the identity:
                                          (u+v)·[(v+w)x(w+u)] = 2u·(vxw)
         Use MATLAB's built-in :functions cross                                        and dot, calculate the value of the
         leftand right sides of the identity.
     19. The dot product can be used for determining the
        angle between two vecton:
                                                                                                                z
                                      e = cos
                                              -
                                               • --"
                                                    (lr1• r�  ..
                                                          r
                                                      r.ll :z
         Use         MATLAB's                built-in        functions               acosd,
         sqrt,           and   dot to find the angle (in degrees)
         between          r1   =     6i-3j +2k          and
         r   2
                 =   21+9J + lOk.
         �that                 lrl   =     Jr:i .
     20 Use MAILAB to show that the angle inscribed                                                            y
        in a semi-circle is a right angle. Use the follow
         ing steps           in a script file to calculate the angle.
         Define a variable with the value of the x coordi
         nate of point  A. Determine the y coordinate of
         point A using the equation x2+y:z = R2. Define
         vectors that con-espond to the position of points A, B, and C and use them for
         determining position vectorsr.4B r..cc.
                                          and        Calculate theangle ex in two ways.
                                                             =
                                                                                      ·
                                                                       -                         and th en by using the equa-
              b using
         First y                   a
                                          (:::;;� ,
                                     the equation
                                                                   cos  1       1     11
                      r r
         tion a sm-•(l ..cB ..td\.
                         =                   X
                      lr.ullr..cd)                       Both should give 90°.
     21. The position as a function of time                    (x(t),y(t))                   y
         of a projectile      fired with             a   speed of v0 at an                                          '
        angle        a is given by                                                                                      '
                                                                                                                            '
                     =                                   =
                                                                                                                                \
          x(t)           v0cosa t                y(t)        v0sina. t- !gt2                                                        \
                                                          2
                                      ·                                     ·
                          = 9.81 m/s2• The polar coordinates of
                                                                                                                                    \
         where       g                                                                                                                  \
                                                                                                                                        \   X
         the projectile at                time t are (r(t), 8(1)),                  where
         r(t)        =   ,/x(t)2+y(t)2           and         tan8(t)        =       ;�:� .   Consider       the     case            where
         v0      =   162m/sand ex = 70°. Determine                                  r(t) and 8(t)   for   t = 1, 6, 11, . .. , 3ls.
3.9 Problems                                                                                                          91
      22. Use MATLAB to show that the sum of the infinite series                           I 2n.�      converges to
                                                                                          n=O
          e
              2
                  •   Do this by computing the sum for:
          (a) n         =   5 , (b)   n   =   10,    (c) n    =    50
          For each part create a vector               n   in which the first element is 0, the increment is
          1 and the last term is 5, 10, or 50. Then use element-by-element calculations to
                                                                             �
          create a vector in which the elements are 2 . Finally, use MATLAB's built-in
                                                                            n.
          function sum to sum the series. Compare the values to                               e
                                                                                                  2
                                                                                                      (use format
          long to display the numbers).
      23. Use MATLAB to show that the sum of the infmite series                              I <91n10)n       con-
                                                                                             n= I
          verges to 1n 10 . Do this by computing the sum for
          (a) n         =   10, (b) n     =    50,    (c) n    =      100
          For each part, create a vector n in which the frrst element is 1, the increment is
          1 and the last term is 10, 50 or 100. Then use element-by-element calculations
                                                            (9/10 n
          to create a vector in which the elements are            ) . Finally, use MAT-
                                                                                      n
          LAB's built-in function sum to sum the series. Compare the values to ln10
          (use format long to display the numbers).
      24. According to Zeno's paradox any object in motion must arrive at the halfway
          point before it can arrive at its destination. Once arriving at the halfway point,
          the remaining distance is once again divided in half and so on to infmity.
          Since it is impossible to complete this process, Zeno concluded all motion
          must be an illusion. Letting the length be unity, Zeno's paradox can be written
          in terms of the infinite sum                I .!.n      =   1 . To see how quickly this series con-
                                                      n= I2
          verges to 1, compute the sum for:
          (a)         n=   5,   (b) n = 10,     (c)    n=     40
          For each part create a vector n in which the first element is 1, the increment is
          1, and the last term is 5 , 10, or 40. Then use element-by-element calculations to
          create a vector in which the elements are                         .!. . Finally, use the MATLAB built-
                                                                             n
                                                                            2
          in function sum to add the terms of the series. Compare the values obtained in
          parts        (a), (b), and (c) with the value of 1.
92                                                            Chapter 3: Mathematical Operations with Arrays
                                  cos(2x)-1                   .
     25.   Show that       lim                    =
                                                          4
                           x-70    cosx-1
           Do this by first creating a vector x that has the elements 1.0, 0.5, 0.1, 0.01,
           0.001, and 0.0001. Then, create a new vectoryin which each element is deter-
                                                                       cos(2x)
           mined from the elements of                 x       by
                                                                        cosx-
                                                                                 � 1 . Compare the elements of y
           with the value 4 (use format long to display the numbers).
                            . x113-1          4
     26.   Show that       bm                     .
                           x-7Ixll4_1
                                          =
                              --              -
                                              3
           Do this by first creating a vector x that has the elements 2.0, 1.5, 1.1, 1.01,
           1.001, 1.00001, and 1.0000001. Then, create a new vector yin which each ele
                                                                                   x113-1
           ment is determined from the elements of x by � . Compare the elements
                                                                                   X   -1
           ofywith the value        4/3   (use format long to display the numbers).
     27.   The demand for water during a fire is often the most important factor in the
           design of distribution storage tanks and pumps. For communities with popula
           tions less than 200,000, the demand Q (in gallons/min) can be calculated by:
                                     Q    1020Jil(l-0.01Jil)
                                                      =
           where P is the population in thousands. Set up a vector for P that starts at 10
           and increments by 10 up to 200. Use element-by -element computations to
           determine the demand Q for each population in P.
     28.   The ideal gas equation states that                      P   =
                                                                           �
                                                                           n T
                                                                               ,   where P is the pressure, V is the
           volume, T is the temperature, R     0.08206 (L atm)/(mol K) is the gas con
                                                                  =
           stant, and n is the number of moles. Real gases, especially at high pressure,
           deviate from this behavior. Their response can be modeled with the van der
           Waals equation
                                                                    nRT _n2a
                                                      p
                                                                   V-nb
                                                              =
                                                                          J12
           where   a   and b are material constants. Consider                          1
                                                                          1 ) of nitrogen  mole ( n   =
           gas at T 300K. (For nitrogen gas a
                       =
                                                             2         2
                                                     1.39 (L atm)/mol , and b
                                                                           =       0.0391                     =
           L/mol.) Create a vector with values of Vs for 0.1� V� 1 L, using increments
           of 0.02 L. Using this vector calculate P twice for each value of V, once using
           the ideal gas equation and once with the van der Waals equation. Using the
                                                                                               p
           two sets of values for P, calculate the percent of error                           ( ide� -Pwaals 100) for
                                                                                                      waals
           each value of V. Finally, by using MATLAB's built-in function max, deter
           mine the maximum error and the corresponding volume.
3.9 Problems                                                                                                    93
      29. Create the following three matrices:
                                       1
                                      [ �  -3 5                 [0 :-2 1                   -3 4
                                                                                           [0 ]      -1
                                 A=    2 2 4             B=     5   1   -6           c=          8 2
                                      -20    6                  2   7   -1                 -3 5 3
          (a)    Calculate A+ B and B +A to show that addition of matrices is commuta
                 tive.
          (b)    Calculate A+(B+C) and (A+ B)+C to show that addition of matrices is
                 associative.
          (c)    Calculate 3(A+C) and 3A + 5C to show that, when matrices are multi
                 plied by a scalar, the multiplication is distributive.
          (d) Calculate A*(B+C) and A* B+ A*C to show that matrix multiplication is
                 distributive.
      30. Use the matrices A, B, and C from the previous problem to answer the follow
          ing:
          (a)    Does A*B= B*A?                                         (b)   Does A*(B*C)       =   (A*B)*C?
      31. Create a 4 x 4 matrix A having random integer values between 1 and 10. Call
          the matrix A and, using MATLAB, perform the following operations. For each
          part explain the operation.
          (a) A* A                            (b) A.*A                         (c) A\A
          (d)    A. I A                       (e)   det   (A)                  (e)   inv   (A)
      32. The magic square is an arrangement of numbers in a square grid in such a way
          that the sum of the numbers in each row, and in each column, and in each
          diagonal is the same. MATLAB has a built-in function                         magic (n) that
          returns an      n   x n magic square. In a script file create a         (6 x 6) magic square,
          and then test the properties of the resulting matrix by fmding the sum of the
          elements in each row, in each column and in both diagonals. In each case, use
          MATLAB's built-in function              sum.   (Other functions that can be useful are
          diag and fliplr.)
      33. Solve the following system of three linear equations:
                                              - 4x+3y+z= -18.2
                                                  5x+6y- 2z     =   -48.8
                                             2x- 5y+4.5z        =   92.5
94                                                    Chapter 3: Mathematical Operations with Arrays
     34. Solve the following system of five linear equations:
                                       2.5a-b+3c+ 1.5d-2e          =   57. 1
                                           3a+4b-2c+2.5d-e         =   27.6
                                           -4a + 3b + c-6d+2e      =   -81.2
                                           2a+3b+c-2.5d+4e         =   -22.2
                                             a+2b+5c-3d+4e         =   -12.2
     35. A food company manufactures five types of 8 oz Trail mix packages using
         different mixtures of peanuts, almonds, walnuts, raisins, and M&Ms. The
         mixtures have the following compositions:
                       Peanuts(oz) Almonds(oz) Walnuts(oz)              Raisins(oz)   M&Ms(oz)
           Mix 1               3                 1             1               2         1
           Mix2                1                 2             1               3         1
           Mix3                1                 1            0                3         3
           Mix4                2                 0            3                1         2
           Mix5                1                 2            3                0         2
         How many packages of each mix can be manufactured if 128 lb of peanuts,
         118 lb of almonds, 112 lb of walnuts, 112 lb of raisins, and 104 lb of M&Ms
         are available? Write a system of linear equations and solve.
     36. The electrical circuit shown consists of resis
         tors and voltage sources. Determine i1, i2, i3 ,
         and i4 , using the mesh current method based
         on Kirchhoff's voltage law (see Sample
         Problem 3-4).
     37. The electrical circuit shown consists of
         resistors and voltage sources. Determine
         i1, i2, i3, i4 and i5 , using the mesh current
         method based on Kirchhoff's voltage law
         (see Sample Problem 3-4).
         v,     =   40V, V2    =   30V, V3   =   36V,
         R1     =   160, R2    =   200, R3      =    100
         R4     =   140, R5    =   8 Q, R6   =      16 Q,
         R1     =   10 Q, R8   =   15 0,   R9    =   6 0,
         R 10   =   4 Q.