Add some additional error to your polynomial. For example, try y =f(x) + 0.001 * randn(size(x));. How does the error in the numer- ical derivative vary with step size h?
Question
Add some additional error to your polynomial. For example, try y =f(x) + 0.001 * randn(size(x));. How does the error in the numer- ical derivative vary with step size h?
Solution
As an AI, I'm unable to directly perform computations. However, I can guide you on how to do it.
-
Choose a function for which you know the derivative. For example, let's take f(x) = sin(x). The derivative of this function is f'(x) = cos(x).
-
Add some additional error to your function. In MATLAB, you can use the randn function to generate random numbers. For example, y = f(x) + 0.001 * randn(size(x));. This will add a small random error to your function.
-
Choose different step sizes h. For example, you can choose h = 1, 0.1, 0.01, 0.001, etc.
-
Calculate the numerical derivatives at x = 0, 1, 1.5, and 2 using the forward, backward, and central difference formulas.
Forward difference formula: f'(x) ≈ (f(x+h) - f(x)) / h Backward difference formula: f'(x) ≈ (f(x) - f(x-h)) / h Central difference formula: f'(x) ≈ (f(x+h) - f(x-h)) / (2h)
-
Calculate the actual derivative at x = 0, 1, 1.5, and 2 using the derivative function f'(x) = cos(x).
-
Calculate the error at each x for each step size h and for each numerical derivative. The error is the absolute difference between the numerical derivative and the actual derivative.
-
Plot a log-log graph of error vs step size for each numerical derivative. You should have three graphs, one for each numerical derivative.
-
From the graphs, you can see how the error in the numerical derivative varies with step size h.
Remember, the accuracy of the numerical derivatives depends on the step size h. The smaller the step size, the more accurate the numerical derivative. However, if the step size is too small, you may encounter round-off errors. The added error will likely increase the overall error in the numerical derivative.
Similar Questions
use matlab to do: Calculate the 2nd derivative and higher derivatives of f (x) = 1 + x + x^2 +x^3 + x^4 + x^5 + x^6 + x^7 + x^8 using the finite difference formulae for higher derivatives. How do the errors vary with step size?
use matlab to do: Calculate the 2nd derivative and higher derivatives of f (x) = 1 + x + x^2 +x^3 + x^4 + x^5 + x^6 + x^7 + x^8 using the finite difference formulae for higher derivatives, and use loglog to plot the chart. and use words tell me that how do the errors vary with step size?
use matlab to explain Estimate the error in a numerical derivative and/or integral from the convergence of the solution as the step size is changed. (It’s best to use step sizes that are large enough to avoid round-off error.) Compare your estimate of the error with actual error determined from comparison with the analytical solution, if an analytical solution is available.
Choose different step sizes h and plot a log-log graph of error vs step size to compare the numerical derivatives found using the forward, backward, and central difference formulas with the actual derivative. How accurate are the numerical derivatives at x = 0, 1, 1.5, and 2? At what step sizes do you obtain the minimum errors, and what are the minimum errors (see Sauer figure 5.1)? when x=? can get the minimum errors
4 Third order derivative.a. Use Taylor series to derive the truncation error of the approximationf′′′(x) ≈( −f(x − 2h) + 2f(x − h) − 2f(x + h) + f(x + 2h))/2h^3assuming f ∈ C^5.b. Explain why dividing by h produces no roundoff error if h = 2−k, k ∈ N.c. Assuming that built-in functions return exact answers but that addition/subtraction produce roundoff errors and that h = 2^−k, k ∈ Z, show that the roundoff error RE in computing this expression satisfies the bound |RE| ≤ (K1 + K2h)u/h^3 where K1, K2 depend on f and x. You may use using the bound |θn| <nu/ (1 − nu)d. Hence estimate, in terms of u, the optimal choice for h.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.