write a program to compute an approximate value for the derivative of a function using the finite difference formula f ′ (x) ≈ f(x + h) − f(x) h . (2) Test your program using the function sin(x) for x = 1. Determine the error by comparing with the built-in function cos(x). Plot the magnitude of the error as a function of h, for h = 1 2 , 1 4 , 1 8 , . . . You should use a log scale for h and the magnitude of the error. Is there a minimum value for the magnitude of the error? b) (5 points) Check if the corresponding value of h to the minimum value for the magnitude of the error can be approximately equal to √ eps ? Why?
Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
clc;
close all
clear all
f = @(x) sin(x); % function handler for The function sin(x)
x = 1;% The point at which the function computing the
derivative
k = 1:50;% number of h values tested
h = 2.^(-k);% creating a vector of h of various values as mentioned
in problem
df = (f(x+h) - f(x))./h;% finding the derivative
err = abs(df - cos(x));% finding the error
loglog(h,err) % plotting the figure in log x and log y graph
grid on % grid on command
xlabel('h');% x axis lable
ylabel('error');% y axis label
for i=1:50
if(err(i) == min(err))
H = h(i); % h corresponding to minimum error
end
end
ApproxH = sqrt(abs(3*(4/3-1)-1))*abs(x); % h approx sqrt(exs
mach)
fprintf(' h corresponding to minumum error %e rule of thum h = %e
',H,ApproxH);
OUTPUT
h corresponding to minumum error 3.725290e-09
rule of thum h = 1.490116e-08

Kindly revert for any queries
Thanks.
write a program to compute an approximate value for the derivative of a function using the...
1. Approximate the derivative of each of the following functions using the forward, backward, and centered differ- ence formulas on the grid linspace (-5,5,100) (x+h)-f(z thforward, (r)-fr-h ckward th)-fle-h centered. For each part, make a single plot (with three curves) showing the absolute error at each grid point. (Note that the approximations are undefined at one or both endpoints.) Also state which approximations are exact (within roundoff error) (b) f:x→z? (d) f:Hsin(x) 2. Use the centered difference formula to approximate...
#7. [Extra Credit] is calculus wrong?! Consider f(x) = ex (a) Calculate the derivative of fx) atx 0 using O(h) finite difference (forward and backward) and O(h2) centered finite difference. Vary h in the following manner: 1, 101,102... 1015. (Write a MATLAB script for this purpose and call it pset5_prob7) (b) Modify your script to plot (log-log) the the true percent error in all three cases as a function of h in one plot. (c) In calculus we learned that...
Design and construct a computer program in Java. The following is a plot of the function f(x) = sin(x3) + x2 : In order to illustrate the effects of the two major error sources, rounding and truncation, attempt to determine an approximation to the derivative of f(x) at x = 2.0 radians using the difference approximation given below. (The true answer is 4 + 12 cos(8) or about 2.2539995942966376896). Use the formula: f'(x) ≃ (f(x+h) - f(x)) / h with...
(10 pts) Write a function to call python modules (either re-write or re-use the program you developed before) to calculate the derivative of In(1+x) at X = 1 using the forward difference, central difference and extrapolated dif- ference methods. Also use this function to create a similar log-log plot that compares the absolute value of the approximation error (you can ignore the rounding error) as a function of the size of the intervals used for these three methods. Choose the...
-4 using Estimate the minimum number of subintervals to approximate the value of 5 sin (x9)dx with an error of magnitude less than 2x 10 -6 a. the error estimate formula for the Trapezoidal Rule. b. the error estimate formula for Simpson's Rule. The minimum number of subintervals using the trapezoidal rule is (Round up to the nearest whole number.) The minimum number of subintervals using Simpson's rule is (Round up to the nearest even whole number.)
-4 using Estimate...
please show me a Matlab script that will compute the
total errors of the approximation due to the given function, also
include the panel plot as well, thank you.
1) This problem studies the errors due to the approximation of the first derivative of a given function f(x) using the forward and centered difference methods. For this problem, we consider f(x)=sin(x). a) First, we will investigate the effect of the step size h on the first derivative approximation. Set h=10',...
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...
3. Consider the function f(x) = -0.1.24 – 0.15x3 – 0.522 – 0.25x + 1.2. (a) Obtain the analytical expression (i.e. True or Exact Solution) for the first derivative, Eval- uate its value at 1 =0.5. Box your answer and label it as fexact- (b) Now assume the function is discretized on a grid with uniform spacing of h. Evaluate your finite difference approximation at x = 0.5 using central differencing with step sizes starting at 1 and re- duced...
C++/Computational Physics: Write a program that implements the forward difference routine to calculate a derivative. Use it to evaulate the derivative of the following function at x=0.8 f(x)=sin(cos(x^2))
2. Use the centered difference formula to approximate f(z) for f sin and z1, using h 1, 1/10, 1/100, ...., 1 /1015. Plot the absolute error. Explain the behavior as h decreases. (Hint: Read the last subsection of §11 concerning roundoff error.) Why does this instability not arise with -0?
2. Use the centered difference formula to approximate f(z) for f sin and z1, using h 1, 1/10, 1/100, ...., 1 /1015. Plot the absolute error. Explain the behavior as...