In Section 7.7: Anonymous functions, we saw how to define so-called anonymous functions in Python. The SymPy counterpart is the command Lambda. Note the difference; lambda is a keyword while Lambda is a constructor.
The command Lambda takes two arguments, the symbol of the function's independent variable, and a SymPy expression to evaluate the function.
Here is an example that defines air resistance (also called drag) as a function of speed:
C,rho,A,v=symbols('C rho A v')
# C drag coefficient, A coss-sectional area, rho density
# v speed
f_drag = Lambda(v,-Rational(1,2)*C*rho*A*v**2)
f_drag is displayed as a graphical expression:
This function can be evaluated in the usual way by providing it with an argument:
x = symbols('x')
f_drag(2)
f_drag(x/3)
Which results in the expressions:
It is also possible to create functions in several variables by just providing the first parameter...