Re: Default and head in function argument
- To: mathgroup at smc.vnet.net
- Subject: [mg111668] Re: Default and head in function argument
- From: NP <nomplume69 at gmail.com>
- Date: Mon, 9 Aug 2010 05:15:51 -0400 (EDT)
- References: <i3m42t$hoc$1@smc.vnet.net>
Hi,
Thank you all so much for the helpful solutions with explanations!
On a similar theme, I got the following to work for the case where
options are not constants
Clear[f1];
f1[A_?MatrixQ, epsilon_: Automatic] := Module[{cv = epsilon},
If[cv === Automatic,
cv = IdentityMatrix[Dimensions[A][[1]]] + (1/Det[A]) A,
IdentityMatrix[Dimensions[A][[1]]] + epsilon A]]
f1[{{1, 2}, {3, 4}}]
but not the following (only change is in the second argument)
Clear[f2];
f2[A_?MatrixQ, epsilon:(_?NumericQ):Automatic] :=
Module[{cv = epsilon},
If[cv === Automatic,
cv = IdentityMatrix[Dimensions[A][[1]]] + (1/Det[A]) A,
IdentityMatrix[Dimensions[A][[1]]] + epsilon A]]
f2[{{1, 2}, {3, 4}}]
Thanks in advance!
NP