DavidVerbruggen
DavidVerbruggen

Reputation: 3

How do I incorporate one function into another?

I have to define two separate functions z(x, mu, c) and landau(x, A, mu, c). z = (x-mu)/c and landau = 1.64872*A*np.exp(-0.5(z+np.exp(-z)))

As they share variables I have tried to define z inside the definition of landau as a function itself and not as a function. Also, I have tried to define z as a function outside the definition of landau. However, nothing I try seems to work. Either python tells me "'float' object is not callable" or "bad operant type for unary -: 'function'". Is there a quick fix for this?

landau(1,1,1,1) should give an answer that's roughly equal to 1

def landau(x, A, mu, c):    # Functie Landau met variabelen x, A, c en mu
# A  = amplitude
# c  = schaalparameter
# mu = positieparameter
def z(x, mu, c):
    return (x-mu)/c
return 1.64872*A*np.exp(-0.5(z(x, mu, c)+np.exp(-z(x, mu, c))))

Upvotes: 0

Views: 75

Answers (1)

keithpjolley
keithpjolley

Reputation: 2263

You missed a * in -0.5 * (z(x. At least I'm assuming it's supposed to be a multiplication.

import numpy as np

def landau(x, A, mu, c):    # Functie Landau met variabelen x, A, c en mu
     # A  = amplitude
     # c  = schaalparameter
     # mu = positieparameter
     return 1.64872 * A * np.exp(-0.5 * (z(x, mu, c) + np.exp(-z(x, mu, c))))

def z(x, mu, c):
     return (x - mu) / c
     
landau(1, 1, 1, 1)
0.9999992292814129

Upvotes: 2

Related Questions