I have a system of expressions (matrices) which correspond to increasing orders of precision in a theory. These expressions are quite complex (require about 40+ lines of code to produce) and are not of equal size (the dimension increases monotonically with the order in the theory). For this reason, I have resigned myself to not creating a single cell which produces all orders.
Suppose I already have functions:
f1[x_, y_] = {{x, y}, {x y, x + y}}
f2[x_, y_] = {{x, y, 0}, {0, x + y, 0}, {1, x - y, x y}}
and I would like to produce a new function
g[(*something*),x_,y_]
such that
g[1,x_,y_] = f1[x_,y_]
g[2,x_,y_] = f2[x_,y_]
Can this be accomplished?
Is there a way to form a conditional on the arguments of a function? Something like
g[j_,x_,y_]=If[j==1,f1[x_,y_],f2[x_,y_]]
This doesn't work, of course, because the first argument isn't actually assigned to j. I guess I'm more surprised it doesn't work to just define g[1,x_,y_] and g[2,x_,y_] individually as above, but it doesn't work.
g[i_Integer, x_, y_] := Symbol["f" <> ToString@i][x, y]
. This question is often asked here... $\endgroup$Switch
. $\endgroup$