I’m sure this is a pretty common question, but I have been unable to find anything that explains what I am trying to do. Say I have some code I use quite frequently:
Clear[\[Sigma]DATA, \[CapitalDelta]\[Sigma]DATA]; \[Sigma]DATA = {}; \[CapitalDelta]\[Sigma]DATA = {}; Do[ PartitionedData = Partition[DATA, j]; Clear[MeanParitionedData]; MeanParitionedData = {}; Clear[MeanDiffList]; MeanDiffList = {}; Do[ AppendTo[MeanParitionedData, Mean[PartitionedData[[i]]]];, {i, 1, Length[PartitionedData]} ]; Do[ AppendTo[ MeanDiffList, (MeanParitionedData[[k + 1]] - MeanParitionedData[[k]])^2];, {k, 1, Length[MeanParitionedData] - 1} ]; \[Sigma] = (1/(Length[MeanParitionedData] - 1)* Total[MeanDiffList[[1 ;;]]])^(1/2); AppendTo[\[Sigma]DATA, \[Sigma]]; AppendTo[\[CapitalDelta]\[Sigma]DATA, \[Sigma]/(2 (Length[ MeanParitionedData] - 1))^(1/2)];, {j, 1, NumberPoints/4} ]
Where DATA
is my input and \[Sigma]DATA
,\[CapitalDelta]\[Sigma]DATA
are my outputs.
How can I save this routine such that I can call it with a short line E.g. RoutineName[DATA]
and this would output my two lists \[Sigma]DATA
,\[CapitalDelta]\[Sigma]DATA
which I can then plot or do whatever I want with.
Note: I am aware that the routine is probably not so optimised in Mathematica but I need to keep it in this structure for a few reasons.
Thanks!