Try specifying your function as MyWavelet[n_,opts:OptionsPattern[]] (documentation) and define Options to your function Method->"PrimalLowpass",Precision->$MachinePrecision, like this:
Options[MyWavelet] ={Method->"PrimalLowpass",Precision->$MachinePrecision}
To actually construct all this as a function, you need to put certain steps as a Module, and some outside as auxiliary functions. First you will need to do this:
Clear[rootlist, prod, normalizer, polyn, h]
Then something like the following should work. Notice how I've cascaded the use of prec to some of the auxiliary functions and made them two-parameter functions. Because prec is used as a parameter in the definition of rootlist, it needs to be outside that set of Module definitions. If I had not put the definition of rootlist inside the curly braces defining the names of modularized variables, i.e. I had written Module[{rootlist, prod...},rootlist= x/.insidehalf[n,prec], this wouldn't have been necessary.
p[n_, x_] := Sum[Binomial[n - 1 + j, j]*x^j, {j, 0, n - 1}]
pol[n_, z_] := Expand[z^(n - 1)*p[n, (1 - (z + 1/z)/2)/2]]
roo[n_, prec_] := NSolve[pol[n, x] == 0, x, prec]
absgreater[x1_, x2_] := Abs[x1] < Abs[x2]
sroo[n_, prec_] := Sort[roo[n, prec], absgreater]
insidehalf[n_, prec_] := Take[sroo[n, prec], n - 1]
MyWavelet[n_Integer?Positive, opts : OptionsPattern[]] :=
With[{prec = OptionValue[Precision]},
Module[{rootlist = x /. insidehalf[n, prec], prod, normalizer,
polyn, h, w},
prod = Expand[Product[(w - rootlist[[j]]), {j, 1, n - 1}]];
normalizer = prod 2^(n - 1/2) /. w -> 1;
polyn = Expand[(1 + w)^n*prod/normalizer];
h = Reverse[N[CoefficientList[polyn, w], prec]];
Table[(-1)^(j - 1) h[[2*n - j]], {j, 0, 2*n - 1}]
]]
Note that you have small imaginary parts that you might not want:
MyWavelet[3, Precision -> 32]
{-0.03522629188570953660274066471551 +
0.*10^-33 I, -0.0854412738820266616928191691818 + 0.*10^-33 I,
0.1350110200102545886963899066994 + 0.*10^-32 I,
0.4598775021184915700951519421476 +
0.*10^-32 I, -0.8068915093110925764944936040887 + 0.*10^-32 I,
0.3326705529500826159985115891390 + 0.*10^-33 I}
You can get rid of them using Chop.
By the way, the Method doesn't currently do anything, but I assume this is a cut-down version of the real problem.
Lengthofhappears to be2num. You could feedhtoMyWaveletand derivenfrom it. – Xerxes Mar 3 at 5:29