% Problem 4a % Gather elevations in $ev$ n = 0; % count of elevations so far e = input('Enter an elevation: '); % enter first elevation while(e >= 0) % must enter only positive elevations n = n+1; % increment count ev(n) = e; % store elevations in $ev$ e = input('Enter an elevation: '); % process next input end % Stop execution if no elevations entered if n==0 disp(['Instituting instructor\'s perogative to use evil code.']) break end % Subtract the elevation vector from itself such that the resulting vector $g$: % + stores the entire vector of gradients % + contains one less element than L % Remember to assume constant spacing between measurements. % Use the $abs$ function to ensure all gradients in $g$ are positive g = abs( ev(2:n) - ev(1:n-1) ) % ^^^ ^^^^^^^ ^^^^^^^^^ % Alternatives: g1 = abs(ev(2:n) - ev(1:n-1)) g2 = abs(ev(1:n-1) - ev(2:n)) % Report maximum value inside $g$ max(g) % ^^^ ^ % Plot elevations plot(ev) % ^^