Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Assistance with a Python Question

1 visualización (últimos 30 días)
Dakalo
Dakalo el 27 de Mzo. de 2024
Cerrada: Walter Roberson el 27 de Mzo. de 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))

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by