Semiintegration and fractional calculus

Version 1.0

Initializations

BeginPackage["SemiIntegration`"];

(* Exported symbols added here with SymbolName::usage *) 

SemiIntegrateList::usage="SemiIntegrateList[data] takes a list of {x, y} data and returns a semi-integrated list.\nSemiIntegrateList[data, δ] takes a vector list of data with spacing δ between elements in the data, and returns a semi-integrated list.";

FractionalIntegrateList::usage="FractionalIntegrateList[data, α] takes a list of {x, y} data and returns a fractionally integrated list of order α. Fractional integration parameter α is between 0 and -1 where -1 is a full integration. The α parameter is negative because a derivative of order -1 is an integration. \nFractionalIntegrateList[data, α, δ] takes a vector list of data with spacing δ between elements of the data, and returns an integrated list of integration order α.";

Unprotect[SemiIntegrateList,FractionalIntegrateList];

Begin["`Private`"]
(* Implementation of the package *)

Clear[SemiIntegrateList,FractionalIntegrateList];

SetAttributes[SemiIntegrateList, ReadProtected];
SetAttributes[FractionalIntegrateList, ReadProtected];

SyntaxInformation[SemiIntegrateList]={"ArgumentsPattern"->{_,___}};

SyntaxInformation[FractionalIntegrateList]={"ArgumentsPattern"->{_,_,___}};

SemiIntegrateList[data_?VectorQ,Δ_]:=Module[{len=Length[data],kernel,list},

kernel=1/Sqrt[len-Range[len,2,-1]+.5];
list=ListCorrelate[{1,1},data];
(0.5*(Sqrt[((Abs[Δ])/π)]))*ListConvolve[kernel,list,{1,1},0]
];

SemiIntegrateList[data:{{_,_}..}]:=Module[{len=Length[data],Δ,column1,column2,kernel,list,tmp},

Δ=data[[2,1]]-data[[1,1]];
column1=Most[data[[All,1]]]-0.5*Δ;
column2=data[[All,2]];
kernel=1/Sqrt[len-Range[len,2,-1]+.5];
list=ListCorrelate[{1,1},column2];
tmp=(0.5*(Sqrt[((Abs[Δ])/π)]))*ListConvolve[kernel,list,{1,1},0];
Transpose[{column1,tmp}]
];

FractionalIntegrateList[data_?VectorQ,α_Real/;-1.<α<0.,Δ_]:=Module[{len=Length[data],kernel,list},

kernel=Table[(len-i+0.5)^(-α-1), {i, len,2,-1}];
list=ListCorrelate[{1,1},data];
(0.5*((Abs[Δ])^(-α))/Gamma[-α])*ListConvolve[kernel,list,{1,1},0]
];

FractionalIntegrateList[data:{{_,_}..},α_Real/;-1.<α<0.]:=Module[{len=Length[data],Δ,column1,column2,kernel,list,tmp},

Δ=data[[2,1]]-data[[1,1]];
column1=Most[data[[All,1]]]-0.5*Δ;
column2=data[[All,2]];
kernel=Table[(len-i+0.5)^(-α-1), {i, len,2,-1}];
list=ListCorrelate[{1,1},column2];
tmp=(0.5*((Abs[Δ])^(-α))/Gamma[-α])*ListConvolve[kernel,list,{1,1},0];
Transpose[{column1,tmp}]
];

End[];

Protect[SemiIntegrateList,FractionalIntegrateList];

EndPackage[]

Usage

Full discussion on how these functions are created can be found in Appendix 2 of Simulating Electrochemical Reactions with Mathematica.

Needs["SemiIntegration`"]

(* create some data *)
data1=Table[Exp[i]/(((1+Exp[i]))^2),{i,20,-20,-0.01}];
data2=Transpose[{Range[20,-20,-0.01],data1}];

ListLinePlot[data2,PlotRange->All]

Semi integrate.

ListLinePlot@SemiIntegrateList[data1,-.01]
ListLinePlot@SemiIntegrateList[data2]

ListLinePlot@FractionalIntegrateList[data1,-0.5,.01]
ListLinePlot@FractionalIntegrateList[data2,-0.5]

Fractionally integrate.

ListLinePlot@FractionalIntegrateList[data1,-0.95,.01]
ListLinePlot@FractionalIntegrateList[data2,-0.95]

ListLinePlot[FractionalIntegrateList[data1,-0.05,.01],PlotRange->All]
ListLinePlot[FractionalIntegrateList[data2,-0.05],PlotRange->All]