Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constants and independent variables in function definitions

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)?

like image 640
Chris Avatar asked Feb 22 '23 04:02

Chris


1 Answers

All of those options are possible, and each is reasonable in some circumstance.

Present in the list of arguments:

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

Only the independent variables:

Globally defined a value

a = 3.14;
f[x_, y_] := (x^2 - a^2)^2 + x^2 y^2

As optional argument

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.

like image 80
Mr.Wizard Avatar answered Apr 26 '23 14:04

Mr.Wizard