This page provides solutions to exercise 3.1.48 in each of our target CASs.
The script file...
% Script file containing a solution to exercise 3.2 #48 % Author: R Smyth % Version: 1.0 7/30/2013 % (a) Plot f(x) = x + 5/x over [0.5, 4] x = linspace(.5, 4, 100); y = x + 5./x; plot( x, y ); axis equal; % Set aspect ratio so x and y ticks have the same spacing. title('y = x + 5/x', 'FontSize', 15); % (b) Enter difference quotient as a function of step size syms h q; q = ( (1+h+5/(1+h)) - (1+5/1) )/h; % (c) Find limit of q as h -> 0. disp('The limit of the difference quotients for f(x)=x+5/x at x=1 as step-size goes to 0 is ...'); m = limit( q, h, 0 ) % (d) Graph secant lines y=f(1)+ q (x-1) for h=3,2,1 together with graph of f and tangent line at x=1. figure; % Create a new figure window. plot( x, y ); % Plot f in new window. axis equal; title('y = x + 5/x with select secants and tangent at x=1'); hold on % Secants y3 = (1+5/1) + subs(q,h,3)*(x-1); y2 = (1+5/1) + subs(q,h,2)*(x-1); y1 = (1+5/1) + subs(q,h,1)*(x-1); plot( x, y3, 'r', x, y2, 'r', x, y1, 'r' ); % Tangent y = (1+5/1) + m*(x-1); plot( x, y, 'g' ); % Choose a nice viewing window. axis([0.5 4 3.5 10]);
can be downloaded from this link (
exercise3_2_48.m).
Store the M-file on MATLAB's path, and execute it
from the command window by
entering its name exercise3_2_48
(without the .m
file extension) to produce ...
>> exercise3_2_48 The limit of the difference quotients for f(x)=x+5/x at x=1 as step-size goes to 0 is ... m = -4
and the figures
and
.
Note especially the use of the subs() command to substitute numerical values for variables in symbolic expressions. The percentage sign % is used to introduce comments which are ignored by the MATLAB interpreter.