Info

This question is closed. Reopen it to edit or answer.

Assistance with a Python Question

1 view (last 30 days)
Dakalo
Dakalo on 27 Mar 2024
Closed: Walter Roberson on 27 Mar 2024
Hi Guys, I'm practicing how to use python in numerical analysis but I am currently facing a problem with question 2. I did question 1 but I have no idea where to start with question 2. Can you please help me with this?
#Question 1
import math
def create_difference_approximations():
forward_diff_approx = lambda f, x, h: (f(x + h) - f(x)) / h
backward_diff_approx = lambda f, x, h: (f(x) - f(x - h)) / h
central_diff_approx = lambda f, x, h: (f(x + h) - f(x - h)) / (2 * h)
return[forward_diff_approx, backward_diff_approx, central_diff_approx]
#Testing the function
f = lambda x: math.sin(0.5 * math.sqrt(x))
print('Question 1: forward: ', forward_diff_approx(f, 1.0, 0.125))
print('Question 1: backward: ', backward_diff_approx(f, 1.0, 0.125))
print('Question 1: central: ', central_diff_approx(f, 1.0, 0.125))

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!