Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using your preferred code editor (e.g. VSCode), in a Python script, write code to answer the following problem. Derivatives can be approximated by finite differences
Using your preferred code editor (e.g. VSCode), in a Python script, write code to answer the following problem.
Derivatives can be approximated by finite differences in several ways, for instance 22 f(x + h)-f(x) h 22 d. h f(x+h)-f(x-h) 2h 22 Assuming f to be differentiable, in the limit h 0, all three expressions are equivalent and exact, but for finite h there are differences. Further discrepancies also arise when using finite precision arithmetic. 4.1 Estimate numerically the derivative of f(x) = cos(x) at x = 1 using the three expressions given above and different step sizes h. Use at least 50 logarithmically spaced values h [10-16, 10 - ] [2 marks] 4.2 Display the absolute difference between the numerical results and the exact value of the derivative, against h in a doubly logarithmic plot. You should format the plot so that the data presentation is clear and easy to understand. [2 marks] 4.3 Describe and interpret your results in no more than 250 words Hint: run the code below [3 marks] h = le-14 print(1 + h - 1) print((1 + h - 1) /h) Derivatives can be approximated by finite differences in several ways, for instance 22 f(x + h)-f(x) h 22 d. h f(x+h)-f(x-h) 2h 22 Assuming f to be differentiable, in the limit h 0, all three expressions are equivalent and exact, but for finite h there are differences. Further discrepancies also arise when using finite precision arithmetic. 4.1 Estimate numerically the derivative of f(x) = cos(x) at x = 1 using the three expressions given above and different step sizes h. Use at least 50 logarithmically spaced values h [10-16, 10 - ] [2 marks] 4.2 Display the absolute difference between the numerical results and the exact value of the derivative, against h in a doubly logarithmic plot. You should format the plot so that the data presentation is clear and easy to understand. [2 marks] 4.3 Describe and interpret your results in no more than 250 words Hint: run the code below [3 marks] h = le-14 print(1 + h - 1) print((1 + h - 1) /h)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started