Page 314 - Numerical Analysis Using MATLAB and Excel
P. 314

Chapter 7  Finite Differences and Interpolation



                % size(xxi) = size(yyi) = size(zzi) = 111  71
                disp('size(xxi)'); size(xxi); disp('size(yyi)'); size(yyi); disp('size(zzi)'); size(zzi)
                size(xxi), size(yyi), size(zzi)
                zzi=interp2(x,y,z,xxi,yyi,'cubic'); % Cubic interpolation − interpolates
                % all combinations of xxi and yyi and constructs the matrix zzi
                mesh(xxi,yyi,zzi);              % Plot smoothed data
                hold on;
                [xx,yy]=meshgrid(x,y);          % Grid with original data
                plot3(xx,yy,z,'*k'); axis([0 175  0 275  500 503]); grid off; box off
                xlabel('x−axis, m'); ylabel('y−axis, m'); zlabel('Height, meters above sea level');
                title('Map of Rectangular Land Parcel')
                hold off;
                % max(x) returns the largest element of vector x
                % max(A) returns a row vector which contains the maxima of the columns
                % in matrix A. Likewise max(zzi) returns a row vector which contains the
                % maxima of the columns in zzi. Observe that size(max(zzi)) = 1  71
                % and size(max(max(zzi))) = 1  1
                zmax=max(max(zzi))              % Estimates the peak of the terrain
                % The 'find' function returns the subscripts where a relational expression
                % is true. For Example,
                % A=[a11 a12 a13; a21 a22 a23; a31 a32 a33] or
                % A=[−1 0 3; 2 3 −4; −2 5 6];
                % [i,j]=find(A>2)
                % returns
                % i =
                %
                %    2
                %    3
                %    1
                %    3
                %
                %
                % j =
                %
                %    2
                %    2
                %    3
                %    3
                % That is, the elements a22=3, a32=5, a13=3 and a33=6
                %  satisfy the condition A>2
                % The == operator compares two variables and returns ones when they
                %  are equal, and zeros when they are not equal
                %
                [m,n]=find(zmax==zzi)
                % m =

               7−36                             Numerical Analysis Using MATLAB® and Excel®, Third Edition
                                                                             Copyright © Orchard Publications
   309   310   311   312   313   314   315   316   317   318   319