Page 72 - Applied Numerical Methods Using MATLAB
P. 72

PROBLEMS   61
                        means the solution for which the residual error (||Ax − b||)isthe
                        minimum over the many solutions.
            1.15 Operations on Vectors
                (a) Find the mathematical expression for the computation to be done by
                    the following MATLAB statements.

                     >>n = 0:100; S = sum(2.^-n)
                (b) Write a MATLAB statement that performs the following computation.

                                        10000             2

                                                1        π
                                                       −
                                             (2n + 1) 2   8
                                         n=0
                 (c) Write a MATLAB statement which uses the commands prod() and
                    sum() to compute the product of the sums of each row of a 3 × 3
                    random matrix.
                (d) How does the following MATLAB routine “repetition(x,M,m)” con-
                    vert a given row vector sequence x to make a new sequence y ?


                     function y = repetition(x,M,m)
                     ifm==1
                      MNx = ones(M,1)*x; y = MNx(:)’;
                     else
                      Nx = length(x); N = ceil(Nx/m);
                      x = [x zeros(1,N*m - Nx)];
                      MNx = ones(M,1)*x;
                      y = [];
                      for n = 1:N
                        tmp = MNx(:,(n - 1)*m + [1:m]).’;
                        y = [y tmp(:).’];
                      end
                     end


                 (e) Make a MATLAB routine “zero_insertion(x,M,m)”, which inserts
                    m zeros just after every Mth element of a given row vector sequence
                    x to make a new sequence. Write a MATLAB statement to apply the
                    routine for inserting two zeros just after every third element of x =
                    [ 1372       49 ]toget

                                y = [ 1370       024      900 ]

                 (f) How does the following MATLAB routine “zeroing(x,M,m)” convert
                    a given row vector sequence x to make a new sequence y?
   67   68   69   70   71   72   73   74   75   76   77