0

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)))) 
2
  • I suggest you start with defining two separate functions. Try to call them and see what happens. You can update this question with your entire code, plus full error tracebacks. Commented Jan 18, 2021 at 14:14
  • 2
    Took a quick look and you're missing an operator between -0.5 and the open parenthesis in -0.5(z... Commented Jan 18, 2021 at 14:15

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

btw, nothing wrong with having z defined in landau like you did. not sure if one way or the other is the preferred style.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.