(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 44734, 842]*) (*NotebookOutlinePosition[ 45415, 865]*) (* CellTagsIndexPosition[ 45371, 861]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Content", "Section"], Cell["\<\ In ionchromatigraphy the contant of the eluent ion changes with the \ concentration of the eluted ion. The change of the eluent ion faslifies the \ measured conductivity. This code calculates the eluen concentration and corrects the \ conductivities and peak height for this effect, obtaining values that are not \ distorted by the eluent ion\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Constants", "Section"], Cell[BoxData[ \(\(\(\[IndentingNewLine]\)\(\(\(cK = 10^\((\(-6.37\)\ )\)\ 10^3\) \)\(;\)\(\ \ \)\( (*equilibrium\ \ carbonat\ constant\ in\ base\ units\ Mol/ m^3\ *) \)\(\[IndentingNewLine]\)\(\(\(HLam = \ 350\ 10^\(-4\)\)\(\ \ \)\) \)\(;\)\(\ \)\( (*\ equivalent\ conductivity\ of\ H + \ in\ S\ m^2/Mol\ *) \)\(\[IndentingNewLine]\)\(\(\(HCO3Lam = \ 45\ \ 10^\(-4\)\)\(\ \)\) \)\(;\)\(\ \ \)\( (*\ equivalent\ conductivity\ of\ HCO3\ S\ m^2/ Mol\ *) \)\(\[IndentingNewLine]\)\(\(\(ClLam = \ 76\ \ 10^\(-4\)\)\(\ \ \)\) \)\(;\)\( (*\ equivalent\ conductivity\ of\ Cl\ S\ m^2/ Mol\ *) \)\(\[IndentingNewLine]\)\(\(\(c = \ 4.2\)\(\ \)\) \)\(;\)\(\ \ \)\( (*\ total\ carbonate\ concentration*\ in\ Mol/m^3\ *) \)\(\[IndentingNewLine]\)\(\(temp0 = \ 25\) \)\(;\)\(\ \ \)\( (*\ Temp . \ for\ which\ the\ above\ constants\ are\ valid\ *) \)\)\)\)], \ "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell["Graphical User Interface", "Section"], Cell[BoxData[{\(Needs["\"];\), "\n", \ \(Needs["\"];\), "\n", RowBox[{\(Off[General::"\"];\), "\[IndentingNewLine]", "\[IndentingNewLine]"}], "\n", RowBox[{ RowBox[{ RowBox[{"inputwg", "=", " ", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{ StyleBox["Widget", "Output"], "[", \("\", \ {"\" \[Rule] 350, \ "\" \[Rule] 210}\), "]"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[Rule]", RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{\("\" \[Rule] {{0. , 15.11}, {1.287, 15.39}, {2.574, 15.67}, {5.147, 16.23}, {10.29, 17.39}, {12.87, 18.01}, {25.74, 21.18}, {64.34, 32.27}, {128.7, 54.11}, {257.4, 101.1}, {386. , 148.6}, {514.7, 194.1}, {643.4, 241. }}\), "\[IndentingNewLine]", ",", \(PropertyValue["\", Name -> \ "\"]\), "\[IndentingNewLine]", ",", StyleBox[\("\" -> {True, True}\), "Program"], StyleBox["\[IndentingNewLine]", "Program"], ",", \({"\", \ \ "\"} -> \ {"\", "\"}\)}], "\[IndentingNewLine]", "}"}], ",", " ", \(Name -> "\"\)}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], "]"}], "\[IndentingNewLine]", ",", \({WidgetFill[]\[IndentingNewLine], Widget["\", {"\" \[Rule] "\", BindEvent["\", Script[ins[]]]}]\[IndentingNewLine], Widget["\", {"\" \[Rule] "\", BindEvent["\", Script[del[]]]}]\[IndentingNewLine]}\), "\[IndentingNewLine]", ",", " ", \({\[IndentingNewLine]\ \ \ Widget["\", \ {"\" -> "\"}], WidgetAlign[]\[IndentingNewLine], Widget["\", {"\" -> "\<35\>", \ "\" \[Rule] "\<20\>", "\" \[Rule] PropertyValue["\"]}, Name -> "\"]\[IndentingNewLine], WidgetAlign[], Widget["\", {"\" \[Rule] "\"}]\ }\), "\[IndentingNewLine]", ",", " ", \({\[IndentingNewLine]\ \ \ Widget["\", \ {"\" -> "\"}], WidgetAlign[]\[IndentingNewLine], Widget["\", {"\" -> "\<4.2\>", \ "\" \[Rule] "\<20\>", "\" \[Rule] PropertyValue["\"]}, Name -> "\"]\[IndentingNewLine], WidgetAlign[], Widget["\", {"\" \[Rule] "\"}]\ \ }\), "\[IndentingNewLine]", ",", " ", \({\[IndentingNewLine]\ \ \ Widget["\", \ {"\" -> "\"}], WidgetAlign[]\[IndentingNewLine], Widget["\", {"\" \[Rule] ToString[ 76. \ \ 10^\(-4\)], "\" \[Rule] \ "\<20\>", "\" \[Rule] PropertyValue["\"]}, Name -> "\"]\[IndentingNewLine], WidgetAlign[], Widget["\", {"\" \[Rule] "\"}]\ \ }\), "\[IndentingNewLine]", " ", "\[IndentingNewLine]", ",", \(Widget["\", {"\" \[Rule] \ "\", "\" -> PropertyValue["\"]}, Name -> "\"]\), "\[IndentingNewLine]", "\[IndentingNewLine]", ",", \({WidgetFill[]\[IndentingNewLine], Widget["\", {"\" -> "\", BindEvent["\", Script[writeFile[]]]}]\[IndentingNewLine], Widget["\", {"\" -> "\", BindEvent["\", Script[ getFile[]]]}]\[IndentingNewLine]\ \[IndentingNewLine], Script[getName[ mode_] := \ \((\[IndentingNewLine]Widget["\", Name \[Rule] "\"]; \ \[IndentingNewLine]SetPropertyValue[{"\", \ "\"}, \ False]; \ \[IndentingNewLine]SetPropertyValue[{"\", \ "\"}, \ \ \[IndentingNewLine]PropertyValue[{"\", "\"}]]; \ \[IndentingNewLine]returnValue = InvokeMethod[{"\", mode}, \ Null]; \[IndentingNewLine]If[ returnValue\ === PropertyValue[{"\", \ "\"}], PropertyValue[{PropertyValue[{"\\ ", "\"}], \ \ "\"}]\[IndentingNewLine]\[IndentingNewLine]]\[IndentingNewLine]\ \[IndentingNewLine])\)]\[IndentingNewLine], Script[getFile[] := Module[{name, dat}, \[IndentingNewLine]If[\((name = getName["\"])\) =!= Null, \[IndentingNewLine]dat = Import[ name, "\"]; \[IndentingNewLine]\ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, ToString[ dat[\([\(-4\), 1]\)]]]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, ToString[ dat[\([\(-3\), 1]\)]]]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, ToString[ dat[\([\(-2\), 1]\)]]]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, ToString[ dat[\([\(-1\), 1]\)]]]; \[IndentingNewLine]dat = Drop[dat, \(-4\)]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, dat]\[IndentingNewLine]]\[IndentingNewLine]]]\ \[IndentingNewLine], Script[writeFile[] := Module[{name, dat}, \[IndentingNewLine]If[\((name = getName["\"])\) =!= Null, \[IndentingNewLine]dat = PropertyValue[{"\", "\"}]; \ \[IndentingNewLine]AppendTo[dat, {\ ToExpression[ PropertyValue[{"\", "\"}]], 0. }]; \[IndentingNewLine]AppendTo[ dat, {\ ToExpression[ PropertyValue[{"\", \ "\"}]], 0. }]; \[IndentingNewLine]AppendTo[ dat, {\ ToExpression[ PropertyValue[{"\", \ "\"}]], 0. }]; \[IndentingNewLine]AppendTo[ dat, {\ ToExpression[ PropertyValue[{"\", \ "\"}]], 0. }]; \[IndentingNewLine]Export[name, dat, "\"]\[IndentingNewLine]]\ \[IndentingNewLine]]]\[IndentingNewLine], Script[ins[] := Module[{row}, \[IndentingNewLine]If[ Length[ PropertyValue[{"\", \ "\"}]] \[Equal] 0, row = \(-1\), \[IndentingNewLine]row = PropertyValue[{"\", "\"}]; If[row < 0, Return[]];]; \[IndentingNewLine]InvokeMethod[{"\ \", "\"}, row + 1, {0, 0}]; \[IndentingNewLine]InvokeMethod[{"\<\ InputTable\>", "\"}, row + 1, row + 1];\[IndentingNewLine]]]\[IndentingNewLine],\ Script[del[] := Module[{row}, \[IndentingNewLine]row = PropertyValue[{"\", \ "\"}]; If[row < 0, Return[]]; \ \[IndentingNewLine]InvokeMethod[{"\", "\"}, row]; \[IndentingNewLine]If[ Length[ PropertyValue[{"\", \ "\"}]] > row, \[IndentingNewLine]\(InvokeMethod[{"\<\ InputTable\>", "\"}, row, row];\)];\[IndentingNewLine]]]\ \[IndentingNewLine]\[IndentingNewLine]}\)}], "\[IndentingNewLine]", "}"}]}], "]"}]}], ";"}], "\n"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"reswg", "=", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{\({Widget["\", {"\" -> "\"}], \[IndentingNewLine]Widget["\", {"\" -> \ "\"}, Name -> "\"]}\), ",", " ", "\[IndentingNewLine]", \(WidgetSpace[10]\), ",", "\[IndentingNewLine]", \(Widget["\", {"\" -> \ "\"}, WidgetLayout \[Rule] {"\" \[Rule] Center}]\), ",", "\[IndentingNewLine]", RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{ StyleBox["Widget", "Output"], "[", \("\", \ {"\" \[Rule] 350, \ "\" \[Rule] 100}\), "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ "\"\\"", "\[Rule]", "\[IndentingNewLine]", RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{\(PropertyValue["\", Name -> \ "\"]\), "\[IndentingNewLine]", ",", StyleBox[\("\" -> False\), "Program"], "\[IndentingNewLine]", ",", \({"\", \ \ "\"} -> \ {"\", "\", "\", \ "\"}\)}], "\[IndentingNewLine]", "}"}], "\[IndentingNewLine]", ",", " ", \(Name -> "\"\)}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], "]"}], "\[IndentingNewLine]", ",", "\[IndentingNewLine]", "\[IndentingNewLine]", \(WidgetSpace[10]\), ",", "\[IndentingNewLine]", \(Widget["\", {"\" -> \ "\"}, WidgetLayout \[Rule] {"\" \[Rule] Center}]\), ",", "\[IndentingNewLine]", RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"\"\\"", "\[Rule]", RowBox[{ StyleBox["Widget", "Output"], "[", \("\", \ {"\" \[Rule] 300, \ "\" \[Rule] 120}\), "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ "\"\\"", "\[Rule]", "\[IndentingNewLine]", RowBox[{ StyleBox["Widget", "Output"], "[", RowBox[{"\"\\"", ",", RowBox[{"{", "\[IndentingNewLine]", RowBox[{\(PropertyValue["\", Name -> \ "\"]\), "\[IndentingNewLine]", ",", StyleBox[\("\" -> False\), "Program"], "\[IndentingNewLine]", ",", \({"\", \ \ "\"} -> \ {"\", "\", \ "\"}\)}], "\[IndentingNewLine]", "}"}], "\[IndentingNewLine]", ",", " ", \(Name -> "\"\)}], "]"}]}]}], "\[IndentingNewLine]", "}"}]}], "]"}]}], "\[IndentingNewLine]", "}"}]}], "]"}]}], ";"}], "\n"}], "\[IndentingNewLine]", RowBox[{\(residueswg = Widget["\", {\[IndentingNewLine]Widget["\", {}, Name \[Rule] "\", WidgetLayout \[Rule] {"\" \[Rule] {True, \ Maximize}}], \ \[IndentingNewLine]{\[IndentingNewLine]Widget["\", {"\" -> \ "\"}, WidgetLayout \[Rule] {"\" \[Rule] {False, False}}], \ \[IndentingNewLine]Widget["\", {}, Name \[Rule] "\"], \ \[IndentingNewLine]WidgetFill[], \[IndentingNewLine]Widget["\", \ {"\" -> "\", BindEvent["\", Script[replotres[]]]}]\[IndentingNewLine]}\ \[IndentingNewLine]}, WidgetLayout \[Rule] {"\" \[Rule] {True, \ True}}];\), "\[IndentingNewLine]", "\[IndentingNewLine]", \( (*\ \ \(**\)\(\(*\)\(\ \)\(\(main\)\(\ \)\(\ **\)\)\(*\)\)\ *) \)}], "\n", \(tabbedwg := Widget["\", {\[IndentingNewLine]WidgetGroup[{\ \[IndentingNewLine]inputwg, \[IndentingNewLine]reswg, \ \[IndentingNewLine]Widget["\", {"\" \[Rule] Widget["\", {"\" \[Rule] 350, \ "\"\ \[Rule] 200}]}, Name \[Rule] "\", \[IndentingNewLine]WidgetLayout \ \[Rule] {"\" \[Rule] {True, \ Maximize}}], \[IndentingNewLine]Widget["\", {}, Name \[Rule] "\", \[IndentingNewLine]WidgetLayout \[Rule] \ {"\" \[Rule] {True, \ Maximize}}], \[IndentingNewLine]Widget["\", {}, Name \[Rule] "\", \[IndentingNewLine]WidgetLayout \[Rule] {"\ \" \[Rule] {True, \ Maximize}}], \[IndentingNewLine]residueswg\ \[IndentingNewLine]\[IndentingNewLine]}\[IndentingNewLine], WidgetLayout \[Rule] {"\" \[Rule] {Tabs, Top, {"\", "\", "\", "\ \", "\", "\"}}}\[IndentingNewLine]]\ \[IndentingNewLine], {\[IndentingNewLine]Widget["\", {"\" -> \ "\", BindEvent["\", Script[calc[]\ ]\ ]}], \[IndentingNewLine]WidgetFill[], \ \[IndentingNewLine]Widget["\", {"\" -> "\", BindEvent["\", Script[docu[]\ ]\ ]}]\[IndentingNewLine]}\ \[IndentingNewLine], Script[\[IndentingNewLine]Needs["\\ "]; \[IndentingNewLine]Needs["\"];\ \[IndentingNewLine]]\[IndentingNewLine], Script[fitfun[dat_, model_, var_] := Block[{t}, Off[DesignedRegress::"\"]; t = Regress[dat, model, var, \[IndentingNewLine]RegressionReport \[Rule] \ {BestFit, RSquared}, \[IndentingNewLine]Weights \[Rule] If[\ PropertyValue[{"\", \ "\"}], Prepend[1/Drop[dat[\([All, 1]\)], 1], 1] // N, \ Automatic\ ], IncludeConstant \[Rule] False]; \[IndentingNewLine]Off[ DesignedRegress::"\"]; t]\[IndentingNewLine]]\[IndentingNewLine], Script[\[IndentingNewLine]calc[] := Block[{tk, cond25, corrcond, expr, $DisplayFunction = Identity, out, x, res, temp}, \[IndentingNewLine]If[ InvokeMethod[{"\", "\"}, 0, 0] =!= 0. , Print["\"]\ \[IndentingNewLine], \[IndentingNewLine]temp = \ ToExpression[ PropertyValue[{"\", "\"}]]; \ \[IndentingNewLine]c = \ ToExpression[ PropertyValue[{"\", "\"}]]; \ \[IndentingNewLine]ClLam = \ ToExpression[ PropertyValue[{"\", "\"}]]; \ \[IndentingNewLine]tk = searchtk[ 10^\(-4\)\ InvokeMethod[{"\", \ "\"}, 0, 1], temp]; tk = 0.02216; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, ToString[ tk]]; \[IndentingNewLine]\[IndentingNewLine]cond25 = \ \ \(PropertyValue[{"\", "\"}]\)[\([All, 2]\)]\ 10^\(-4\)\ \((1 + \ 0.023\ \ \((temp - 20)\))\)/\ \((1 + \ tk\ \ \((temp - temp0)\))\); \[IndentingNewLine]conc = \ \ \(PropertyValue[{"\", "\"}]\)[\([All, 1]\)]\ ; \[IndentingNewLine]out = $Output; $Output \ = {}; \[IndentingNewLine]corrcond = CorrCond\ /@ \ cond25; \[IndentingNewLine]$Output = out; \[IndentingNewLine]\[IndentingNewLine]peak = Transpose[{conc, 10^4 \((cond25 - cond25[\([1]\)])\)}]; \ \[IndentingNewLine]corrpeak = Transpose[{conc, 10^4 \((corrcond - corrcond[\([1]\)])\)}]; \ \[IndentingNewLine]std10 = Sqrt[\((1/\((Length[conc] - 1)\))\) Plus @@ \ \((\((peak[\([All, 2]\)] - \((\(BestFit\ /. fitfun[peak, {x}, x]\) /. x \[Rule] conc)\))\)^2)\)]; \ \[IndentingNewLine]std20 = Sqrt[\((1/\((Length[conc] - 1)\))\) Plus @@ \ \((\((corrpeak[\([All, 2]\)] - \((\(BestFit\ /. fitfun[corrpeak, {x}, x]\) /. x \[Rule] conc)\))\)^2)\)]; \ \[IndentingNewLine]res = {{"\", std10, std20}}; \[IndentingNewLine]std1 = Sqrt[\((1/\((Length[conc] - 1)\))\) Plus @@ \ \((\((peak[\([All, 2]\)] - \((\(BestFit /. fitfun[peak, {1, x}, x]\) /. x \[Rule] conc)\))\)^2)\)]; \ \[IndentingNewLine]std2 = Sqrt[\((1/\((Length[conc] - 1)\))\) Plus @@ \((\ \((corrpeak[\([All, 2]\)] - \((\(BestFit /. fitfun[corrpeak, {1, x}, x]\) /. x \[Rule] conc)\))\)^2)\)]; \ \[IndentingNewLine]AppendTo[ res, {"\", std1, std2}]; \[IndentingNewLine]q10 = Coefficient[BestFit /. fitfun[peak, {x, x^2}, x], x^2]; \[IndentingNewLine]q20 = Coefficient[BestFit /. fitfun[corrpeak, {x, x^2}, x], x, 2]; \[IndentingNewLine]AppendTo[ res, {"\", q10, q20}]; \[IndentingNewLine]q1 = Coefficient[BestFit /. fitfun[peak, {1, x, x^2}, x], x^2]; \[IndentingNewLine]q2 = Coefficient[ BestFit /. fitfun[corrpeak, {1, x, x^2}, x], x, 2]; \[IndentingNewLine]AppendTo[ res, {"\", q1, q2}]; \[IndentingNewLine]rr10 = RSquared\ /. \ \((fitfun[peak, {x}, x])\); \[IndentingNewLine]rr20 = RSquared\ /. \((\ fitfun[corrpeak, {x}, x])\); \[IndentingNewLine]AppendTo[ res, {"\", rr10, rr20}]; \[IndentingNewLine]rr1 = RSquared\ /. \ \((fitfun[peak, {1, x}, x])\); \[IndentingNewLine]rr2 = RSquared\ /. \((\ fitfun[corrpeak, {1, x}, x])\); \[IndentingNewLine]AppendTo[ res, {"\", rr1, rr2}]; \[IndentingNewLine]\[IndentingNewLine]res = Map[ToString[NumberForm[#, 3]] &, res, {2}]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, res]; \[IndentingNewLine]\[IndentingNewLine]diff1 = peak[\([All, 2]\)] - \((\((pol1 = BestFit /. fitfun[peak, {x}, x])\) /. x -> peak[\([All, 1]\)])\); \[IndentingNewLine]diff2 = corrpeak[\([All, 2]\)] - \((\((pol2 = BestFit /. fitfun[corrpeak, {x}, x])\) /. x \[Rule] corrpeak[\([All, 1]\)])\); \[IndentingNewLine]res = Transpose[{peak[\([All, 2]\)], corrpeak[\([All, 2]\)], diff1, diff2}]; \ \[IndentingNewLine]SetPropertyValue[{"\", "\"}, res]; \[IndentingNewLine]\[IndentingNewLine]expr = Graphics`MultipleListPlot`MultipleListPlot[corrpeak, peak, AxesLabel \[Rule] {"\", "\"}, PlotJoined \[Rule] True, PlotStyle \[Rule] {Dashing[{}], Dashing[Dot]}, PlotLabel \[Rule] "\"]; \[IndentingNewLine]expr = Show[expr, PlotRange \[Rule] All]; \[IndentingNewLine]SetPropertyValue[{"\<\ plPeaks\>", \ "\"}, ToString[expr, InputForm]]; \ \[IndentingNewLine]\[IndentingNewLine]expr = Show[expr, PlotRange \[Rule] {{0, .5\ Max[conc]}, {0, .45 Max[peak[\([All, 2]\)]]}}]; \ \[IndentingNewLine]SetPropertyValue[{"\", \ "\"}, ToString[expr, InputForm]]; \[IndentingNewLine]\[IndentingNewLine]\ \[IndentingNewLine]expr = Plot[{pol2, pol1}, {x, 0, Max[conc]}, AxesLabel \[Rule] {"\", "\"}, PlotLabel \[Rule] "\", PlotStyle \[Rule] {Dashing[{}], Dashing[{0.01, 0.01}]}, Prolog \[Rule] {PointSize[0.015], Point /@ corrpeak, Point /@ \ peak}]; \[IndentingNewLine]expr = Show[expr, PlotRange \[Rule] All]; \[IndentingNewLine]SetPropertyValue[{"\", \ "\"}, ToString[expr, InputForm]]; \ \[IndentingNewLine]\[IndentingNewLine]expr = Graphics`MultipleListPlot`MultipleListPlot[ Transpose[{conc, diff2}], Transpose[{conc, diff1}], AxesLabel \[Rule] {"\", "\"}, PlotJoined \[Rule] True, PlotStyle \[Rule] {Dashing[{}], Dashing[Dot]}, PlotLabel \[Rule] "\"]; \[IndentingNewLine]expr = Show[expr, PlotRange \[Rule] All]; \[IndentingNewLine]SetPropertyValue[{"\<\ plResidues\>", \ "\"}, ToString[expr, InputForm]]; \ \[IndentingNewLine]\[IndentingNewLine]SetPropertyValue[{"\", \ "\ \"}, ToString[Length[conc], InputForm]];\[IndentingNewLine]\[IndentingNewLine]]\ \[IndentingNewLine]]\[IndentingNewLine]], \[IndentingNewLine]Script[ docu := Block[{}, \ \[IndentingNewLine]Graphics`MultipleListPlot`MultipleListPlot[corrpeak, peak, AxesLabel \[Rule] {"\", "\"}, PlotJoined \[Rule] True, PlotStyle \[Rule] {Dashing[{}], Dashing[Dot]}, PlotLabel \[Rule] "\"]; \[IndentingNewLine]Plot[{pol2, pol1}, {x, 0, Max[conc]}, AxesLabel \[Rule] {"\", "\"}, PlotLabel \[Rule] "\", PlotStyle \[Rule] {Dashing[{}], Dashing[{0.01, 0.01}]}, Prolog \[Rule] {PointSize[0.015], Point /@ corrpeak, Point /@ \ peak}]; \ \[IndentingNewLine]ListPlot[{Transpose[{conc, diff2}], Transpose[{conc, diff1}]}, AxesLabel \[Rule] {"\", "\"}, PlotLabel \[Rule] "\", PlotStyle \[Rule] {Dashing[{}], Dashing[{0.01, 0.01}]}]; \[IndentingNewLine]Print["\", {std10, sdt20}]; \[IndentingNewLine]Print["\", {std1, sdt2}]; \[IndentingNewLine]Print["\", {q10, q20}]; \[IndentingNewLine]Print["\", {q1, q2}]; \[IndentingNewLine]Print["\", {rr10, rr20}]; \[IndentingNewLine]Print["\", {rr1, rr2}]; \[IndentingNewLine]Print[]; \ \[IndentingNewLine]Print["\", peak]; \[IndentingNewLine]Print["\", corrpeak];\[IndentingNewLine]]\[IndentingNewLine]], \[IndentingNewLine]\ \[IndentingNewLine]Script[ replotres[] := Block[{$DisplayFunction = Identity, diff1, diff2, conc0n}, \[IndentingNewLine]n = ToExpression[ PropertyValue[{"\", "\"}]]; \ \[IndentingNewLine]diff1 = \(Take[peak, n]\)[\([All, 2]\)] - \((\((pol1 = BestFit /. fitfun[Take[peak, n], {x}, x])\) /. x \[Rule] \(Take[peak, n]\)[\([All, 1]\)])\); \[IndentingNewLine]diff2 = \(Take[ corrpeak, n]\)[\([All, 2]\)] - \((\((pol2 = BestFit /. fitfun[Take[corrpeak, n], {x}, x])\) /. x \[Rule] \(Take[corrpeak, n]\)[\([All, 1]\)])\); \[IndentingNewLine]conc0 = Take[conc, n]; \[IndentingNewLine]\[IndentingNewLine]expr = Graphics`MultipleListPlot`MultipleListPlot[ Transpose[{conc0, diff2}], Transpose[{conc0, diff1}], AxesLabel \[Rule] {"\", "\"}, PlotJoined \[Rule] True, PlotStyle \[Rule] {Dashing[{}], Dashing[Dot]}, PlotLabel \[Rule] "\"]; \[IndentingNewLine]expr = Show[expr, PlotRange \[Rule] All]; \[IndentingNewLine]SetPropertyValue[{"\<\ plResidues\>", \ "\"}, ToString[expr, InputForm]];\[IndentingNewLine]\[IndentingNewLine]]\ \[IndentingNewLine]]\[IndentingNewLine]}];\), "\[IndentingNewLine]", "Null"}], "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell["Calculations", "Section"], Cell[BoxData[ \(\(\( (*Cl\ from\ cond\ without\ activity\ \ *) \)\(\[IndentingNewLine]\)\(ClConc[cond_] := Module[{res, H, HCO3, H2CO3, H0, HCO30, H2CO30, Cl, r, r0, var}, \[IndentingNewLine]\[IndentingNewLine]eq = {\ \[IndentingNewLine]H\ \ HCO3\ /\ H2CO3\ == \ cK, \[IndentingNewLine]H\ - \ HCO3 - \ Cl\ \[Equal] \ 0, \[IndentingNewLine]HCO3\ + \ H2CO3\ == \ c, \[IndentingNewLine]\[IndentingNewLine]H\ \ HLam\ + \ Cl\ ClLam\ + \ HCO3\ \ HCO3Lam == \ cond\ \[IndentingNewLine]}; \[IndentingNewLine]var = {H, HCO3, H2CO3, Cl}; \[IndentingNewLine]r = Solve[eq, var]\ \ // Simplify; \[IndentingNewLine]r = Select[r, FreeQ[#, Complex] &]; \[IndentingNewLine]r = Select[r, FreeQ[#, a_ /; a < 0] &]; \[IndentingNewLine] (*\(Print["\", \ \ \((H\ HLam + \ HCO3\ \ HCO3Lam\ + \ \ Cl\ ClLam\ \ )\)\ \ /. \ r];\)*) \[IndentingNewLine]If[Length[r] =!= 1, Print["\"]; Return[], r = r[\([1]\)]]; \[IndentingNewLine]\[IndentingNewLine]Cl /. r\[IndentingNewLine]]\[IndentingNewLine]\[IndentingNewLine]\ \[IndentingNewLine] (*search\ Tk\ of\ ion . \ cond = \ value\ from\ the\ instrument, \ temp = \ measurement\ \(\(temp\)\(.\)\)*) \[IndentingNewLine] searchtk[cond_, temp_] := Module[{tk, dtk, cond25, conc, outp, i = 0}, \[IndentingNewLine]If[ temp == 25. , Return[0.023]]; \[IndentingNewLine]outp = $Output; \ $Output = {}; \ \[IndentingNewLine]tk = 0.025; dtk = 0.001; \[IndentingNewLine] (*ensure\ vald\ start\ Tk\ *) \[IndentingNewLine]\[IndentingNewLine]While[\((ClConc[ cond\ \((1 + 0.023\ \ \((temp - 20)\))\)/\ \((1 + \ tk \((\ temp - 25)\))\)])\) === Null, tk -= dtk; \[IndentingNewLine]If[\(++i\) > 100, $Output = outp; Print["\"]; Return[]]\[IndentingNewLine]]; Print["\", tk]; \[IndentingNewLine]While[ dtk > 10^\(-6\), \[IndentingNewLine]cond25 = cond\ \((1 + \ 0.023\ \ \((temp - 20)\))\)/\ \((1 + \ tk\ \((\ temp - 25)\))\); conc = ClConc[cond25]; \[IndentingNewLine]If[ conc === Null\[IndentingNewLine], tk = tk - dtk; \ dtk\ *= \ 0.7;\[IndentingNewLine], \(tk = tk + dtk;\)];\[IndentingNewLine]]; \[IndentingNewLine]$Output \ = outp; \[IndentingNewLine]tk\[IndentingNewLine]]\[IndentingNewLine]\ \[IndentingNewLine] (*\ calculates\ conductivity\ from\ chloridconc . \ using\ activity\ from\ Debey - H\[UDoubleDot]ckel\ *) \[IndentingNewLine] TheorCondDH[Cl_, outconc_: False] := Module[{height, res, H, HCO3, H2CO3, r, var, ionenst, activit}, \[IndentingNewLine]eq = {\[IndentingNewLine]H\ \ HCO3\ /\ H2CO3\ == \ cK, \[IndentingNewLine]H\ - \ HCO3 - \ Cl\ \[Equal] \ 0, \[IndentingNewLine]HCO3\ + \ H2CO3\ == \ c\[IndentingNewLine]}; \ \[IndentingNewLine]\[IndentingNewLine]var = {H, HCO3, H2CO3}; \[IndentingNewLine]r = Solve[eq, var]\ \ // Simplify; \[IndentingNewLine]r = Select[r, FreeQ[#, Complex] &]; \[IndentingNewLine]r = Select[r, FreeQ[#, a_ /; a < 0] &]; \[IndentingNewLine]If[ Length[r] =!= 1, Print["\"]; Return[], r = r[\([1]\)]]; \[IndentingNewLine] (*\(\(\({\((ToString /@ \ var)\), var /. r} // Transpose\)\ // MatrixForm\)\ // Print\ ;\)*) \[IndentingNewLine]\[IndentingNewLine]ionenst = 0.5\ \((H\ + \ Cl\ + \ HCO3)\); \[IndentingNewLine]activit = 10^\((\(-\ 0.5091\)\ Sqrt[ ionenst\ 10^\(-3\)])\); (*ionenst\ in\ Mol/ L*) \[IndentingNewLine]\ res = \ \((H\ HLam + \ HCO3\ \ HCO3Lam\ + \ \ Cl\ ClLam\ \ )\) activit\ \ /. \ r; \[IndentingNewLine]If[ outconc, {H, HCO3, H2CO3} /. \ r, res]\[IndentingNewLine]]\[IndentingNewLine]\[IndentingNewLine] (*\ corrects\ given\ cond . \ for\ carbonat\ equ . \ using\ activity\ from\ Debey - H\[UDoubleDot]ckel*) \[IndentingNewLine] CorrCond[cond_] := Module[{res, H, HCO3, H2CO3, H0, HCO30, H2CO30, Cl, r, r0, var, del, i, conc1, conc2, conc3, cd1, cd2, cd3, ionenst, activit}, \[IndentingNewLine]\t\t\t\t\t\t\t\t (*search\ Cl\ conc . \ \ that\ gives\ same\ \(\(cond\)\(.\)\)*) \[IndentingNewLine]\t\t\t\t\t\t \ (*get\ Cl\ without\ activity\ *) \[IndentingNewLine]eq = \ {\[IndentingNewLine]H\ \ HCO3\ /\ H2CO3\ == \ cK, \[IndentingNewLine]H\ - \ HCO3 - \ Cl\ \[Equal] \ 0, \[IndentingNewLine]HCO3\ + \ H2CO3\ == \ c, \[IndentingNewLine]\[IndentingNewLine]H\ \ HLam\ + \ Cl\ ClLam\ + \ HCO3\ \ HCO3Lam == \ cond\ \[IndentingNewLine]}; \[IndentingNewLine]var = {H, HCO3, H2CO3, Cl}; \[IndentingNewLine]r = Solve[eq, var]\ \ // Simplify; \[IndentingNewLine]r = Select[r, FreeQ[#, Complex] &]; \[IndentingNewLine]r = Select[r, FreeQ[#, a_ /; a < 0] &]; \[IndentingNewLine] (*\(If[ Length[r] =!= 1, Print["\"]; Return[], r = r[\([1]\)]];\)*) \[IndentingNewLine]If[ Length[r] \[Equal] 0, Print["\", cond]; r = Cl \[Rule] 0, If[Length[r] =!= 1, Print["\"]; Return[], r = r[\([1]\)]]]; \[IndentingNewLine]\[IndentingNewLine]\ \[IndentingNewLine]\[IndentingNewLine]conc1 = \ Cl /. r; \ \ \ \ \ \ \ \ \ \ (*search\ start\ values\ for\ \ bisection*) \[IndentingNewLine]cd1 = TheorCondDH[conc1]; \[IndentingNewLine]If[cd1 > cond, del = \(-conc1\)/10, del = conc1/10]\ ; \[IndentingNewLine]For[ i = 1, i < 10, \[IndentingNewLine]conc2 = conc1 + del; \ \ If[ conc2 < 0, conc2 = 0]; \[IndentingNewLine]cd2 = \ TheorCondDH[conc2]; \[IndentingNewLine]If[ Sign[\((cd2 - cond)\)\ \ \((cd1 - cond)\)] \[LessEqual] 0, Break[]];\[IndentingNewLine], \(i++\)]; \[IndentingNewLine]\ \[IndentingNewLine]\t\t\t\t\t\t\ \ \ (*\ bisection\ *) \[IndentingNewLine]For[i = 1, i < 10, \[IndentingNewLine]cd3 = \ TheorCondDH[ conc3 = 0.5 \((conc1 + conc2)\)]; \[IndentingNewLine]If[ Abs[cd1 - cond] < Abs[cd2 - cond], cd2 = cd3; \ conc2 = conc3, cd1 = cd3; \ conc1 = conc3];\[IndentingNewLine], \(i++\)]; \[IndentingNewLine]\ \[IndentingNewLine]\t\t\t\t\t\t\t\t (*H2CO3\ conc\ for\ new\ Cl\ \ concentration\ and\ \ Cl = 0\ *) \[IndentingNewLine]{tmp, tmp, H2CO3} = \ TheorCondDH[0.5 \((conc1 + conc2)\), True]; \[IndentingNewLine]{tmp, tmp, H2CO30} = \ TheorCondDH[0. , True]; \[IndentingNewLine]\[IndentingNewLine] \ (*\(\(\({\((ToString /@ \ var)\), var /. r} // Transpose\)\ // MatrixForm\)\ // Print\ ;\)*) \ \[IndentingNewLine]\[IndentingNewLine]\ res = cond\ + \ \ \((H2CO3\ - \ H2CO30)\) \((HLam\ + \ HCO3Lam)\)\ \ \ // Chop; \[IndentingNewLine]\[IndentingNewLine]res\[IndentingNewLine]\ ]\[IndentingNewLine]\[IndentingNewLine] \(On[General::"\"];\)\[IndentingNewLine] \)\)\)], "Input", InitializationCell->True], Cell[BoxData[ RowBox[{"GUIRun", "[", RowBox[{"tabbedwg", ",", StyleBox[\(IncludedScriptContexts\ -> \ {$Context}\), "Program"]}], "]"}]], "Input", InitializationCell->True] }, Open ]] }, FrontEndVersion->"5.1 for Microsoft Windows", ScreenRectangle->{{0, 1600}, {0, 1097}}, AutoGeneratedPackage->Automatic, WindowSize->{1360, 743}, WindowMargins->{{Automatic, 35}, {135, Automatic}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 26, 0, 92, "Section"], Cell[1805, 55, 371, 7, 59, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2213, 67, 28, 0, 92, "Section"], Cell[2244, 69, 1022, 20, 161, "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell[3303, 94, 43, 0, 92, "Section"], Cell[3349, 96, 33321, 593, 5642, "Input", InitializationCell->True] }, Open ]], Cell[CellGroupData[{ Cell[36707, 694, 31, 0, 92, "Section"], Cell[36741, 696, 7769, 136, 2366, "Input", InitializationCell->True], Cell[44513, 834, 205, 5, 35, "Input", InitializationCell->True] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)