I'm learning python and I'm not sure how to pass a string to lambda.
This is a basic example of Riemann sum:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
#f0 = str(input("ingrese funcion:"))
f = lambda x: x**2
sum = 0.0
a = float(input("ingrese límite inferior:"))
b = float(input("ingrese límite superior:"))
n = int(input("ingrese cantidad de subintervalos:"))
i = b-a #la longitud del intervalo
dx = i/n #que diferencia habrá cada vez que evalúes
for xi in np.arange(a,b,dx):
sum += dx*f(xi)
print "Valor de la suma de Riemann de f en [a,b] = " + str(sum)
My idea was to let f0 as a user defined string (e.g. x**2 + 10) and then pass f0 to f. Of course doing that should return an "undefined" error.