I have an equation which I try to plot and work with in Mathematica which is of the form
f(x,y) = (x^2 - a^2)^2 + x^2 y^2
Here x
and y
are independent variables and a
is a constant. What is the standard way of defining a function such as this: should the constants/parameters be present in the list of arguments or should this list just contain the independent variables? Alternatively, should the parameters be present in the argument list but as optional arguments (with default values)?
All of those options are possible, and each is reasonable in some circumstance.
f[x_, y_, a_] := (x^2 - a^2)^2 + x^2 y^2
Or:
f[a_][x_, y_] := (x^2 - a^2)^2 + x^2 y^2
Globally defined a
value
a = 3.14;
f[x_, y_] := (x^2 - a^2)^2 + x^2 y^2
f[x_, y_, a_:3.14] := (x^2 - a^2)^2 + x^2 y^2
You'll need to be more specific regarding your use if I am to provide a more specific answer. The globally defined a
value should be used with caution, but it is certainly not without its place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With