Info

此问题已关闭。 请重新打开它进行编辑或回答。

Assistance with a Python Question

1 次查看(过去 30 天)
Dakalo
Dakalo 2024-3-27
关闭: Walter Roberson 2024-3-27
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))

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by