Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pertinent notions to this question are the derivative of a function (its definit

ID: 3871225 • Letter: P

Question

 Pertinent notions to this question are the derivative of a function (its definition as a limit), the loss of significance in finite precision environment, and the speed/order of an algorithm.  Carefully read the MATLAB code, determine what it does, and complete the command line marked there.  h(1)=1E-2; TRUEV=        ;  % you will need to complete this line for i=2:15   h(i)=h(i-1)/4;   D=(exp((5+h(i))^2)-exp(5^2))/h(i);   error(i)=TRUEV-D; end    format long  % try to remove the long format line to see the difference h, error % try to organize better the printout, so that the entries of % h align with the entries of error  %hint: h=(5+h)-5, therefore D computes the slope %of "something". 

Explanation / Answer

The Program Approximating the derivative of f(x) = ex^2 at x = 5 using limit.

The Program without removing format long command

h(1)=1E-2;
TRUEV=2*5*exp(5^2); % you will need to complete this line
for i=2:15
h(i)=h(i-1)/4;
D=(exp((5+h(i))^2)-exp(5^2))/h(i);
error(i)=TRUEV-D;
end
format long
% try to remove the long format line to see the difference
h, error
% try to organize better the printout, so that the entries of
% h align with the entries of error

%hint: h=(5+h)-5, therefore D computes the slope
%of "something".

OUTPUT

h =

Columns 1 through 4

   0.010000000000000   0.002500000000000   0.000625000000000   0.000156250000000

Columns 5 through 8

   0.000039062500000   0.000009765625000   0.000002441406250   0.000000610351563

Columns 9 through 12

   0.000000152587891   0.000000038146973   0.000000009536743   0.000000002384186

Columns 13 through 15

   0.000000000596046   0.000000000149012   0.000000000037253


error =

   1.0e+09 *

Columns 1 through 4

                   0 -9.260658513262817 -2.300133478265259 -0.574099737762329

Columns 5 through 8

-0.143466670672485 -0.035863055828735 -0.008965388641235 -0.002240826141235

Columns 9 through 12

-0.000561726141235 -0.000141026141235 -0.000017826141235 -0.000177826141235

Columns 13 through 15

-0.000593826141235   0.000762973858765 -0.002411426141235

>>

The Program after removing format long command

h(1)=1E-2;
TRUEV=2*5*exp(5^2); % you will need to complete this line
for i=2:15
h(i)=h(i-1)/4;
D=(exp((5+h(i))^2)-exp(5^2))/h(i);
error(i)=TRUEV-D;
end
% try to remove the long format line to see the difference
fprintf('h error ');
fprintf('%11.12f %11.12f ',[h;error]);
% try to organize better the printout, so that the entries of
% h align with the entries of error

%hint: h=(5+h)-5, therefore D computes the slope
%of "something".

OUTPUT

h                          error
0.010000000000 0.000000000000
0.002500000000 -9260658513.262817382812
0.000625000000 -2300133478.265258789062
0.000156250000 -574099737.762329101562
0.000039062500 -143466670.672485351562
0.000009765625 -35863055.828735351562
0.000002441406 -8965388.641235351562
0.000000610352 -2240826.141235351562
0.000000152588 -561726.141235351562
0.000000038147 -141026.141235351562
0.000000009537 -17826.141235351562
0.000000002384 -177826.141235351562
0.000000000596 -593826.141235351562
0.000000000149 762973.858764648438
0.000000000037 -2411426.141235351562

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote