Here is the code that I have so far:
fun[{data_, p_, n_, min_, max_}] :=
Module[{}, lstplt = LinearModelFit[data, Table[x^i, {i, n}], x];
Print[lstplt[x]]
Print["Fit plotted from min to max temperature in data set range"]
Print[Plot[lstplt[x], {x, min, max}]];
reslist =
Inner[List, {data}[[1, All, 1]], lstplt["FitResiduals"], List];
Print["Fit and data curve"]
Print[Show[ListPlot[data], Plot[lstplt[x], {x, min, max}]]];
Print["Residual Plot"]
Print[ListPlot[reslist]];
bres = Select[reslist, Abs[#[[2]]] > p &];
gres = DeleteCases[reslist, Alternatives @@ bres];
gpoints = gres[[All, 1]] \[Intersection] reslist[[All, 1]];
Print["New data curve excluding points that had poor residual \
values"]
Print[ListPlot[
dataset13 = Select[data, gpoints~MemberQ~First[#] &]]];
Print["New data set"];
Print["Number of points"];
Print[Length[dataset13]];
Return[dataset13];]
data = Table[{x, RandomReal[{-.1, .1}] + x^2}, {x, 0, 15}];
I want to be able to do the following line of code:
fun[fun[data, .04, 2, 0, 15], 1, 3, 0, 15]
without having to type in the argument over and over again. Would NestList be the best way to tackle this? It looks like a nest function problem to me, however I want to be able to change the n value by one after each iteration. How could I simplify this last line that I want to be able to do so that I can type it in one line and say continue to apply the function 'fun' until n has reached some value N?
p
changing in each iteration or is it a typo in the last line? $\endgroup$