4.3. Functions#
You will also work with undefined mathematical functions in addition to variables. These will play an important role in setting up differential equations, where you typically don’t know the function, but only its derivative(s). You can create arbitrary functions of variables. In this case, you make a function of \(x\). First create the function name:
f = sym.Function('f')
Now you can create functions of one or more variables like so:
f(x)

The same UndefinedFunction
can be used to create multivariate functions:
f(x,y)

Test yourself!
Create a function \(H(x,y,z)\)
All variables have been defined with:
x, y, z = sym.symbols('x, y, z')
Click –> Live Code to activate live coding!
x, y, z = sym.symbols('x, y, z')
H = sym.Function('H')
function_correct = H(x,y,z)
function_answer = 0
H = None
function =
check_answer("function",function_correct, check_equation)