Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Assistance with a Python Question

1 Ansicht (letzte 30 Tage)
Dakalo
Dakalo am 27 Mär. 2024
Geschlossen: Walter Roberson am 27 Mär. 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))

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by