%%Matlab code for finding derivative
clear all
close all
%function for which derivative have to find
f=@(x) sin(x);
fprintf('function for which derivative have to find f(x)=')
disp(f)
%derivative of f
ff=@(x,h) (sin(x+h)-sin(x))/h;
%x0 value
x0=1.2;
%all h values
hh=logspace(0,-20,21);
fprintf('\n\t h \tval \t ext_val \t error\n\n')
for i=1:length(hh)
h=hh(i);
val=ff(x0,h);
val_ext=cos(x0);
error=abs(val-val_ext);
fprintf('\t%2.2e \t%f \t%f \t%e
\n',h,val,val_ext,error)
end
%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%%
2. The function fi(xo,h) = sin(xo+h)-sin(xo) can be transformed into another form., f2(xo,h), using the trigonometri...
2. The function fi(xo.h)= sin(xo +h)- sin(xo) can be transformed into another form. f2(xo,h), using the trigonometric formula + sin()-sin() =2cos sin 2 Thus, fi and f have the same values, in exact arithmetic, for any given argument values xo and h. (b) Suggest a formula that avoids cancellation errors for computing the approximation (f(xo +h)- f(xo))/h to the derivative of f(x) = sin(x ) at x xo. Write a MATLAB pro- gram that implements your formula and computes an...
In Python 3.6 Classes and Methods: A class for estimating the derivative of a function f) at the form: takes where h is a small change in x. The goal of this exercise is to use the formula above to differentinte a mat hematical function f(x) implemented as a Python function f(x) Implement class Diff with two special methods. The--init--() method takes in function object and also an optional argument h. The default value of h is le-4. Implement also...