% script to compute and visualize the relation % of the function f(x) = exp(x) and its derivative % via slope triangles at positions -1,0,1, and 2. deltaX = 0.01; x = -4:deltaX:2; y = exp(x); x1 = -2:deltaX:-1; t1 = (x1+2)*exp(-1); x2 = -1:deltaX:0; t2 = (x2+1); x3 = 0:deltaX:1; t3 = x3*exp(1); x4 = 1:deltaX:2; t4 = (x4-1)*exp(2); % plot function and tangents % use default color scheme for plot lines, but reorder color1 = [0, 0.4470, 0.7410]; color2 = [0.8500, 0.3250, 0.0980]; color3 = [0.9290, 0.6940, 0.1250]; color4 = [0.4660, 0.6740, 0.1880]; set(gca,'DefaultLineLineWidth',2) hold on % plot exponential function h0 = plot(x,y, 'Color', 'black'); plot(x1,t1, 'Color', color1); plot(x2,t2, 'Color', color2) plot(x3,t3, 'Color', color3); plot(x4,t4, 'Color', color4) % plot vertical lines plot([-1 -1], [0 exp(-1)], 'Color', color1) plot([0 0], [0 1], 'Color', color2) plot([1 1], [0 exp(1)], 'Color', color3) plot([2 2], [0 exp(2)], 'Color', color4) % plot horizontal lines h1 = plot([-2 -1], [0 0], 'Color', color1); h2 = plot([-1 0], [0 0], 'Color', color2); h3 = plot([0 1], [0 0], 'Color', color3); h4 = plot([1 2], [0 0], 'Color', color4); hold off xlim([-4.1, 2.5]); ylim([0, 7.5]); legendStrings = {'exp(x)', 'slope \Delta 1', 'slope \Delta 2', ... 'slope \Delta 3', 'slope \Delta 4'}; legend([h0 h1 h2 h3 h4], legendStrings, 'Location', 'northwest') % plot figure as pdf w/o large margins using export_fig addpath('altmany-export_fig-9d97e2c') outputFileName = 'exponential_derivatives.pdf'; export_fig(outputFileName, '-q101');