-3
I’m writing an algorithm that calculates the average of continuous variables and I pass to it a function with the specific function:
def media_variavel_continua(func, ini, fim):
return quad(func, ini, fim)
resp = media_variavel_continua(lambda x: (x**2)/3, 1, 3)
It turns out that the average of a continuous variable is the function itself times 'x', so I wanted to be able to rewrite in media_variavel_continua() the passed function.
In the example above the function (x 2)/3 at the end would have to be x*(x 2)/3.
Is there any way to do that?
In that case I believe you can try to make a new
lambda x: x*func(x)
. But I believe that modifying a lambda generically speaking is more complicated.– Naslausky
@Naslausky that worked, thank you!
– Roberto Alves Neto