Skip to main content
added 5 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

##Example

Example

#Possible issues

Possible issues

##Example

#Possible issues

Example

Possible issues

add a reference.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489

but honestly speakingThe $\tilde{f}_s(n)$ is a general finite Fourier sine transform. (This paper is a possible reference. ) I can't understand it very wellmight implement these transforms someday.

but honestly speaking I can't understand it very well.

The $\tilde{f}_s(n)$ is a general finite Fourier sine transform. (This paper is a possible reference. ) I might implement these transforms someday.

Add one new definition for inverse finite Fourier transform, which is suitable for multiple inverse transform.
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
ClearAll[finiteFourierSinTransform, finiteFourierCosTransform, finiteFourierTransform, 
transformToIntegrate]

(#[(h : List | Plus | Equal)[a__], x_, n_] := Function[f, #[f, x, n]] /@ h[a];
    #[a_ b_, {x_, xmin_, xmax_}, n_] /; FreeQ[b, x] := 
     b #[a, {x, xmin, xmax}, n]) & /@ {finiteFourierSinTransform, 
   finiteFourierCosTransform, finiteFourierTransform};
argumentPattern = (#[
      Derivative[i___, j_, k___][head_][var1___, x_, var2___], {x_, xmin_, xmax_}, n_] /;
      Length@{i} === Length@{var1} && j > 0) &;
With[{f = Derivative[i, j - 1, k][head]},
 Evaluate@argumentPattern@
    finiteFourierSinTransform := -((n Pi)/(xmax - xmin)) finiteFourierCosTransform[
    f[var1, x, var2], {x, xmin, xmax}, n];
 
 Evaluate@argumentPattern@
    finiteFourierCosTransform := ((n Pi)/(xmax - xmin)) finiteFourierSinTransform[
     f[var1, x, var2], {x, xmin, xmax}, n] + (-1)^n f[var1, xmax, var2] - 
   f[var1, xmin, var2];
 
 Evaluate@argumentPattern@
    finiteFourierTransform := ((2 I n Pi)/(xmax - xmin)) finiteFourierTransform[
     f[var1, x, var2], {x, xmin, xmax}, 
     n] + (-1)^-n (f[var1, xmax, var2] - f[var1, xmin, var2]);
 
 (#[f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
      n_] :=
     With[{assump = {n ∈ Integers, xmax > xmin, #3}, 
       integral = 
        Function[index, 
         Simplify@Integrate[f #2[(index Pi (x - xmin))/(xmax - xmin)], {x, xmin, xmax}]]},
      Module[{general =
         Assuming[assump, integral@n]}, 
       With[{singularity = 
          If[IntegerQ@n, {}, 
           Union@Join[If[#2 === Cos, {0}, {}], 
             Piecewise[{{{}, # === n}}, #] &@(n /. 
                Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]]},
        Piecewise[{integral@#, n == #} & /@ singularity, general]]
       ]
      ]) & @@@ {{finiteFourierSinTransform, Sin, n > 0}, {finiteFourierCosTransform, Cos,
     n >= 0}};
 
 finiteFourierTransform[
   f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
   n_] :=
  With[{assump = {n ∈ Integers, xmax > xmin}, 
    integral = Function[index, 
      Simplify@Integrate[
        f E^(-((2 I index π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))), {x, xmin, 
         xmax}]]},
   Module[{general =
      Assuming[assump, integral@n]}, 
    With[{singularity = 
       If[IntegerQ@n, {}, 
        Piecewise[{{{}, # === n}}, #] &@(n /. 
           Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]},
     Piecewise[{integral@#, n == #} & /@ singularity, general]]
    ]
   ]
 ]


inverseFiniteFourierSinTransform[f_, n_, {x_, xmin_, xmax_}] := 
 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &[f Sin[(n Pi (x - xmin))/(xmax - xmin)]]

inverseFiniteFourierCosTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) (f /. n -> 0) + 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &@
  Simplify[f Cos[(n Pi (x - xmin))/(xmax - xmin)], n > 0]

inverseFiniteFourierTransform[f_, n_, {x_, xmin_, xmax_}], Re] := 
 1/(xmax - xmin) ((f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) /. 
        n -> 0) + 2 HoldForm@Sum[#, {n, 1, C}] &@
    Simplify[f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) // Re, 
     n ∈ Integers])

inverseFiniteFourierTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) (HoldForm@Sum[#, {n, -C, C}] &@
    Simplify[f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)), 
     n ∈ Integers])

transformToIntegrate[expr_] := 
  expr /. (HoldPattern@#[f_, {x_, xmin_, xmax_}, n_] :> 
        RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)[
          f #2[(n Pi (x - xmin))/(xmax - xmin)] /. 
           x -> \[FormalX]] & @@@ {{finiteFourierSinTransform, 
        Sin}, {finiteFourierCosTransform, Cos}}) /. 
   HoldPattern@finiteFourierTransform[f_, {x_, xmin_, xmax_}, n_] :> 
    RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)@
      Simplify[f E^(-((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))) /. 
        x -> \[FormalX], n ∈ Integers];
ClearAll[finiteFourierSinTransform, finiteFourierCosTransform, finiteFourierTransform, 
transformToIntegrate]

(#[(h : List | Plus | Equal)[a__], x_, n_] := Function[f, #[f, x, n]] /@ h[a];
    #[a_ b_, {x_, xmin_, xmax_}, n_] /; FreeQ[b, x] := 
     b #[a, {x, xmin, xmax}, n]) & /@ {finiteFourierSinTransform, 
   finiteFourierCosTransform, finiteFourierTransform};
argumentPattern = (#[
      Derivative[i___, j_, k___][head_][var1___, x_, var2___], {x_, xmin_, xmax_}, n_] /;
      Length@{i} === Length@{var1} && j > 0) &;
With[{f = Derivative[i, j - 1, k][head]},
 Evaluate@argumentPattern@
    finiteFourierSinTransform := -((n Pi)/(xmax - xmin)) finiteFourierCosTransform[
    f[var1, x, var2], {x, xmin, xmax}, n];
 
 Evaluate@argumentPattern@
    finiteFourierCosTransform := ((n Pi)/(xmax - xmin)) finiteFourierSinTransform[
     f[var1, x, var2], {x, xmin, xmax}, n] + (-1)^n f[var1, xmax, var2] - 
   f[var1, xmin, var2];
 
 Evaluate@argumentPattern@
    finiteFourierTransform := ((2 I n Pi)/(xmax - xmin)) finiteFourierTransform[
     f[var1, x, var2], {x, xmin, xmax}, 
     n] + (-1)^-n (f[var1, xmax, var2] - f[var1, xmin, var2]);
 
 (#[f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
      n_] :=
     With[{assump = {n ∈ Integers, xmax > xmin, #3}, 
       integral = 
        Function[index, 
         Simplify@Integrate[f #2[(index Pi (x - xmin))/(xmax - xmin)], {x, xmin, xmax}]]},
      Module[{general =
         Assuming[assump, integral@n]}, 
       With[{singularity = 
          If[IntegerQ@n, {}, 
           Union@Join[If[#2 === Cos, {0}, {}], 
             Piecewise[{{{}, # === n}}, #] &@(n /. 
                Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]]},
        Piecewise[{integral@#, n == #} & /@ singularity, general]]
       ]
      ]) & @@@ {{finiteFourierSinTransform, Sin, n > 0}, {finiteFourierCosTransform, Cos,
     n >= 0}};
 
 finiteFourierTransform[
   f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
   n_] :=
  With[{assump = {n ∈ Integers, xmax > xmin}, 
    integral = Function[index, 
      Simplify@Integrate[
        f E^(-((2 I index π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))), {x, xmin, 
         xmax}]]},
   Module[{general =
      Assuming[assump, integral@n]}, 
    With[{singularity = 
       If[IntegerQ@n, {}, 
        Piecewise[{{{}, # === n}}, #] &@(n /. 
           Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]},
     Piecewise[{integral@#, n == #} & /@ singularity, general]]
    ]
   ]
 ]


inverseFiniteFourierSinTransform[f_, n_, {x_, xmin_, xmax_}] := 
 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &[f Sin[(n Pi (x - xmin))/(xmax - xmin)]]

inverseFiniteFourierCosTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) (f /. n -> 0) + 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &@
  Simplify[f Cos[(n Pi (x - xmin))/(xmax - xmin)], n > 0]

inverseFiniteFourierTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) ((f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) /. 
        n -> 0) + 2 HoldForm@Sum[#, {n, 1, C}] &@
    Simplify[f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) // Re, 
     n ∈ Integers])

transformToIntegrate[expr_] := 
  expr /. (HoldPattern@#[f_, {x_, xmin_, xmax_}, n_] :> 
        RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)[
          f #2[(n Pi (x - xmin))/(xmax - xmin)] /. 
           x -> \[FormalX]] & @@@ {{finiteFourierSinTransform, 
        Sin}, {finiteFourierCosTransform, Cos}}) /. 
   HoldPattern@finiteFourierTransform[f_, {x_, xmin_, xmax_}, n_] :> 
    RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)@
      Simplify[f E^(-((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))) /. 
        x -> \[FormalX], n ∈ Integers];
ClearAll[finiteFourierSinTransform, finiteFourierCosTransform, finiteFourierTransform, 
transformToIntegrate]

(#[(h : List | Plus | Equal)[a__], x_, n_] := Function[f, #[f, x, n]] /@ h[a];
    #[a_ b_, {x_, xmin_, xmax_}, n_] /; FreeQ[b, x] := 
     b #[a, {x, xmin, xmax}, n]) & /@ {finiteFourierSinTransform, 
   finiteFourierCosTransform, finiteFourierTransform};
argumentPattern = (#[
      Derivative[i___, j_, k___][head_][var1___, x_, var2___], {x_, xmin_, xmax_}, n_] /;
      Length@{i} === Length@{var1} && j > 0) &;
With[{f = Derivative[i, j - 1, k][head]},
 Evaluate@argumentPattern@
    finiteFourierSinTransform := -((n Pi)/(xmax - xmin)) finiteFourierCosTransform[
    f[var1, x, var2], {x, xmin, xmax}, n];
 
 Evaluate@argumentPattern@
    finiteFourierCosTransform := ((n Pi)/(xmax - xmin)) finiteFourierSinTransform[
     f[var1, x, var2], {x, xmin, xmax}, n] + (-1)^n f[var1, xmax, var2] - 
   f[var1, xmin, var2];
 
 Evaluate@argumentPattern@
    finiteFourierTransform := ((2 I n Pi)/(xmax - xmin)) finiteFourierTransform[
     f[var1, x, var2], {x, xmin, xmax}, 
     n] + (-1)^-n (f[var1, xmax, var2] - f[var1, xmin, var2]);
 
 (#[f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
      n_] :=
     With[{assump = {n ∈ Integers, xmax > xmin, #3}, 
       integral = 
        Function[index, 
         Simplify@Integrate[f #2[(index Pi (x - xmin))/(xmax - xmin)], {x, xmin, xmax}]]},
      Module[{general =
         Assuming[assump, integral@n]}, 
       With[{singularity = 
          If[IntegerQ@n, {}, 
           Union@Join[If[#2 === Cos, {0}, {}], 
             Piecewise[{{{}, # === n}}, #] &@(n /. 
                Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]]},
        Piecewise[{integral@#, n == #} & /@ singularity, general]]
       ]
      ]) & @@@ {{finiteFourierSinTransform, Sin, n > 0}, {finiteFourierCosTransform, Cos,
     n >= 0}};
 
 finiteFourierTransform[
   f_ /; AtomQ@f || Quiet@Context@Evaluate@Head[f] === "System`", {x_, xmin_, xmax_}, 
   n_] :=
  With[{assump = {n ∈ Integers, xmax > xmin}, 
    integral = Function[index, 
      Simplify@Integrate[
        f E^(-((2 I index π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))), {x, xmin, 
         xmax}]]},
   Module[{general =
      Assuming[assump, integral@n]}, 
    With[{singularity = 
       If[IntegerQ@n, {}, 
        Piecewise[{{{}, # === n}}, #] &@(n /. 
           Solve[Flatten@{assump, Denominator@Together@general == 0}, n])]},
     Piecewise[{integral@#, n == #} & /@ singularity, general]]
    ]
   ]
 ]


inverseFiniteFourierSinTransform[f_, n_, {x_, xmin_, xmax_}] := 
 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &[f Sin[(n Pi (x - xmin))/(xmax - xmin)]]

inverseFiniteFourierCosTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) (f /. n -> 0) + 2/(xmax - xmin) HoldForm@Sum[#, {n, C}] &@
  Simplify[f Cos[(n Pi (x - xmin))/(xmax - xmin)], n > 0]

inverseFiniteFourierTransform[f_, n_, {x_, xmin_, xmax_}, Re] := 
 1/(xmax - xmin) ((f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) /. 
        n -> 0) + 2 HoldForm@Sum[#, {n, 1, C}] &@
    Simplify[f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)) // Re, 
     n ∈ Integers])

inverseFiniteFourierTransform[f_, n_, {x_, xmin_, xmax_}] := 
 1/(xmax - xmin) (HoldForm@Sum[#, {n, -C, C}] &@
    Simplify[f E^((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin)), 
     n ∈ Integers])

transformToIntegrate[expr_] := 
  expr /. (HoldPattern@#[f_, {x_, xmin_, xmax_}, n_] :> 
        RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)[
          f #2[(n Pi (x - xmin))/(xmax - xmin)] /. 
           x -> \[FormalX]] & @@@ {{finiteFourierSinTransform, 
        Sin}, {finiteFourierCosTransform, Cos}}) /. 
   HoldPattern@finiteFourierTransform[f_, {x_, xmin_, xmax_}, n_] :> 
    RuleCondition@(HoldForm@Integrate[#, {\[FormalX], xmin, xmax}] &)@
      Simplify[f E^(-((2 I n π (x - xmin - (xmax - xmin)/2))/(xmax - xmin))) /. 
        x -> \[FormalX], n ∈ Integers];
deleted 16 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
Rollback to Revision 5
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
Rollback to Revision 4
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
added 1768 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
added 357 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
added 91 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
added 160 characters in body
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading
Source Link
xzczd
  • 68.4k
  • 9
  • 174
  • 489
Loading