(* Package for the Schauder basis and associated functions -- Usage Examples are in Schauder.ma Author: Jack K. Cohen, Colorado School of Mines, 1993 (jkc@keller.mines.colorado.edu) Reference: Meyer, Wavelets Algorithms & Applications, SIAM, 1993 See pages 15-17. *) (* Declaration of public function names in Schauder Basis package *) BeginPackage["Schauder`"]; SchauderTriangle::usage = "SchauderTriangle[(n), x] \n\n SchauderTriangle returns the n^th basis function in the Schauder basis\n for n = -1, 0, 1, 2, ... . The default value of n is 1." SchauderCoefficient::usage = "SchauderCoefficient[f[x], {x, n}] \n\n Compute n^th coefficient in the Schauder expansion of f[x]\n\n Typically issue the command like this:\n SchauderCoefficient[x^2, {x, 2}] " SchauderApproximant::usage = "SchauderApproximant[f[x], {x, nmax}] \n\n Compute Schauder approximation of f[x] using n = -1, 0, 1, ... nmax\n\n Typically issue the command like this:\n SchauderApproximant[x^2, {x, 3}] " Haar::usage = "Haar[(n), x] \n\n Haar returns the n^th basis function in the Haar basis\n for n = 0, 1, 2, ... . The default value of n is 1." HaarCoefficient::usage = "HaarCoefficient[f[x], {x, n}] \n\n Compute n^th coefficient in the Haar expansion of f[x]\n\n Typically issue the command like this:\n HaarCoefficient[x^2, {x, 2}] " DirectHaarApproximant::usage = "DirectHaarApproximant[f[x], {x, nmax}] \n\n Compute Haar approximation of f[x] using n = -1, 0, 1, ... nmax\n Uses Integrate to compute the Haar Approximates (cf. HaarApproximant)\n\n Typically issue the command like this:\n DirectHaarApproximant[x^2, {x, 3}] " HaarApproximant::usage = "HaarApproximant[f[x], {x, nmax}] \n\n Compute Haar approximation of f[x] using n = -1, 0, 1, ... nmax\n Uses Schauder coefficients to compute the Haar Approximates\n\n Typically issue the command like this:\n HaarApproximant[x^2, {x, 3}] " Begin["`private`"]; (* ----- Schauder Basis Functions ----- *) SchauderTriangle[x_] := Which[ 0 <= x <= 1/2, 2x, 1/2 < x <= 1, 2(1-x), True, 0 ] SchauderTriangle[n_Integer?Positive, x_] := Module[{j, power, k}, j = Floor@N@Log[2, n]; power = 2^j; k = n - power; SchauderTriangle[power x - k] ] SchauderTriangle[0, x_] := Which[ 0 <= x <= 1, x, True, 0 ] SchauderTriangle[-1, x_] := Which[ 0 <= x <= 1, 1, True, 0 ] (* ----- End of Schauder Basis Functions ----- *) (* ----- Schauder Expansion Coefficients ----- *) (* Convert user form to internal form *) SchauderCoefficient[f_, {x_, n_}] := SchauderCoefficient[Function[x, f], n] (* Do the work with the internal form *) SchauderCoefficient[f_, n_] := Module[{j, power, k}, j = Floor@N@Log[2, n]; power = 2^j; k = n - power; f[(k + 1/2)/power] - (f[k/power] + f[(k+1)/power])/2 ] /; (* Type Checks *) IntegerQ[n] && Positive[n] SchauderCoefficient[f_, 0] := f[1] - f[0] SchauderCoefficient[f_, -1] := f[0] (* ----- End of Schauder Expansion Coefficients ----- *) (* ----- Schauder Approximant ----- *) (* Convert user form to internal form *) SchauderApproximant[f_, {x_, nmax_}] := SchauderApproximant[Function[x, f], nmax, x] (* need x below *) (* Do the work with the internal form *) SchauderApproximant[f_, nmax_, x_] := Module[{n}, Sum[SchauderCoefficient[f, n] SchauderTriangle[n, x], {n, -1, nmax}] ] /; (* Type Checks *) IntegerQ[nmax] && (nmax >= -1) (* ----- End of Schauder Approximant ----- *) (* ----- Haar Basis Functions ----- *) Haar[x_] := Which[ 0 <= x < 1/2, 1, 1/2 <= x < 1, -1, True, 0 ] Haar[n_Integer?Positive, x_] := Module[{j, power, sqrtpower, k}, j = Floor@N@Log[2, n]; power = 2^j; k = n - power; sqrtpower = 2^(j/2); sqrtpower Haar[power x - k] ] Haar[0, x_] := Which[ 0 <= x < 1, 1, True, 0 ] (* ----- End of Haar Basis Functions ----- *) (* ----- Haar Expansion Coefficients for Direct Expansion ----- *) (* Convert user form to internal form *) HaarCoefficient[f_, {x_, n_}] := HaarCoefficient[Function[x, f], n] (* Do the work with the internal form *) HaarCoefficient[f_, n_] := Module[{x, j, power, k, sqrtpower, temp}, j = Floor@N@Log[2, n]; power = 2^j; k = n - power; sqrtpower = 2^(j/2); temp = Integrate[f[x], {x, k/power, (k+1/2)/power}] - Integrate[f[x], {x, (k+1/2)/power, (k+1)/power}]; sqrtpower temp ] /; (* Type Checks *) IntegerQ[n] && Positive[n] HaarCoefficient[f_, 0] := Module[{x}, Integrate[f[x], {x, 0, 1}] ] (* ----- End of Haar Expansion Coefficients for Direct Expansion ----- *) (* ----- Direct Haar Approximant ----- *) (* Convert user form to internal form *) DirectHaarApproximant[f_, {x_, nmax_}] := DirectHaarApproximant[Function[x, f], nmax, x] (* need x below *) (* Do the work with the internal form *) DirectHaarApproximant[f_, nmax_, x_] := Module[{n}, Sum[HaarCoefficient[f, n] Haar[n, x], {n, 0, nmax}] ] /; (* Type Checks *) IntegerQ[nmax] && (nmax >= 0) (* ----- End of Direct Haar Approximant ----- *) (* ----- Haar Approximant via Schauder Expansion ----- *) (* Convert user form to internal form *) HaarApproximant[f_, {x_, nmax_}] := HaarApproximant[Function[x, f], nmax, x] (* need x below *) (* Do the work with the internal form *) HaarApproximant[f_, nmax_, x_] := Module[{F, t, xx, j, power, n, sqrtpower, sum}, F[xx_] = Integrate[f[t], {t, 0, xx}]; sum = F[1] Haar[0, x]; Do[ j = Floor@N@Log[2, n]; power = 2^j; sqrtpower = 2^(j/2); sum += 2 sqrtpower * SchauderCoefficient[F, n] Haar[n, x], {n, 1, nmax}]; sum ] /; (* Type Checks *) IntegerQ[nmax] && (nmax >= 0) (* ----- End of Haar Approximant via Schauder Expansion ----- *) End[]; Protect[ SchauderTriangle, SchauderCoefficient, SchauderApproximant, Haar, HaarCoefficient, DirectHaarApproximant, HaarApproximant ] EndPackage[];