Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Assistance with a Python Question
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!