(* ::Package:: *)

(************************************************************************)
(* This file was generated automatically by the Mathematica front end.  *)
(* It contains Initialization cells from a Notebook file, which         *)
(* typically will have the same name as this file except ending in      *)
(* ".nb" instead of ".m".                                               *)
(*                                                                      *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs.  Doing so is equivalent   *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end.                                                                 *)
(*                                                                      *)
(* DO NOT EDIT THIS FILE.  This entire file is regenerated              *)
(* automatically each time the parent Notebook file is saved in the     *)
(* Mathematica front end.  Any changes you make to this file will be    *)
(* overwritten.                                                         *)
(************************************************************************)



SimpleFitter[thisNamesForDataColumns_,thisData_] := 
Manipulate[
choicex = Position[thisNamesForDataColumns,choicexname][[1]][[1]];
choicey = Position[thisNamesForDataColumns,choiceyname][[1]][[1]];
(* we then put that into a new array using the "Table" command *)
choicecut = Flatten[Position[thisNamesForDataColumns,choicecutname]][[1]];

(* I take the user's cut-variable, if any, and apply it, throwing away data where the cut variable is outside the range *)
If[UseCut,
SelectedData = Select[thisData,#[[choicecut]] > cutmin && #[[choicecut]] < cutmax &],
SelectedData = thisData
]
;
plotdata = Table[{SelectedData[[i]][[choicex]],SelectedData[[i]][[choicey]]},{i,1,Length[SelectedData]}];

myFit = NonlinearModelFit[plotdata,ToExpression[userEquation],ToExpression[userVariables],x];
GraphicsGrid[{{ Show[
Plot[myFit["BestFit"],{x,0,0.1}],
ListPlot[plotdata,PlotMarkers->{Automatic,Medium}]
]},{Text[myFit["ParameterTable"]]}}
],
{{choicexname,thisNamesForDataColumns[[1]],"x-axis"},thisNamesForDataColumns},
{{choiceyname,thisNamesForDataColumns[[2]],"y-axis"},thisNamesForDataColumns},
{{userEquation,"a*x + b","fit to y="}},
{{userVariables,"{a,b}","with parameters "}},
{{UseCut,False,"Restrict the data?"},{False,True}},
{{choicecutname,thisNamesForDataColumns[[1]],"restricted variable"},thisNamesForDataColumns},
{{cutmin,5,"from min= "},-10000,10000},
{{cutmax,10000,"to max="},-10000,10000},


ControlType->{PopupMenu,PopupMenu,InputField,InputField,Checkbox,PopupMenu,InputField,InputField}
]



