Question:
I'm trying to pull together a graph with labelled axes, a title, and an inset box with information relating to the plot such as the y-intercept (A in this code) and it's uncertainty. However, none of the conditions beyond the initial plot implements, and outputs 3 or 4 pages of errors, but can't see what the error is, even with the description
Code:
fit = NonlinearModelFit[dataHist5, A*Exp[-k*t], {A, k}, t,
Weights -> 1/uncertainties^2];
hLife = Log[2]/Around[k, \[Sigma]k]
seA = Around[A, \[Sigma]A]
halfLife = hLife[[1]] /. fit["BestFitParameters"]
sehalfLife =
hLife[[2]] /. fit["BestFitParameters"] /. \[Sigma]k ->
fit["ParameterErrors"][[2]]
uncertainties = dataHist5[[All, 2, 2]];
Show[ListPlot[dataHist5],
Plot[fit[x], {x, 0, 800}, PlotRange -> All,
PlotLabel -> "Decay Curve of Phosphorus-31 by \[Beta]^{+} Emission",
PlotTheme -> "Detailed", PlotStyle -> Red,
LabelStyle -> {Black, Bold}, {0.85, 0.75}],
Frame -> {{True, False}, {True, False},
FrameLabel -> {"Time /s",
"Counts Recorded in the Previous 15 seconds"},
ImageSize -> {700, 500}},
Inset[Framed[
Grid[{{"Run 0"}, {"N=" Length[
dataHist5] "/50"}, {"A=" seA}, {"t_{frac{1}{2}}=" PlusMinus[
halfLife,
sehalfLife]}, {"\[Chi]^{2}=" fit[
"ANOVATableSumsOfSquares"][[2]]}, {"Reduced \[Chi]^{2}=" fit[
"ANOVATableMeanSquares"][[2]]}}], Background -> White,
RoundingRadius -> 5, Scaled[{.85, .9}]]]]
Data:
dataHist5 = {{Around[16.5, 1.5],
Around[77.8, 8.8]}, {Around[34.5, 1.5],
Around[60.5, 8.0]}, {Around[52.5, 1.5],
Around[63.8, 8.0]}, {Around[106.5, 1.5],
Around[42.4, 6.5]}, {Around[124.5, 1.5],
Around[41.7, 6.5]}, {Around[142.5, 1.5],
Around[14.6, 3.8]}, {Around[160.5, 1.5],
Around[33.9, 5.8]}, {Around[178.5, 1.5],
Around[29.4, 5.4]}, {Around[196.5, 1.5],
Around[33.5, 5.8]}, {Around[214.5, 1.5],
Around[30.9, 5.6]}, {Around[232.5, 1.5],
Around[31.1, 5.8]}, {Around[250.5, 1.5],
Around[21.5, 4.6]}, {Around[268.5, 1.5],
Around[4.3, 2.1]}, {Around[286.5, 1.5],
Around[6.4, 2.5]}, {Around[322.5, 1.5],
Around[7.5, 2.7]}, {Around[340.5, 1.5],
Around[4.5, 2.1]}, {Around[358.5, 1.5],
Around[11., 3.3]}, {Around[376.5, 1.5],
Around[14.0, 3.7]}, {Around[394.5, 1.5],
Around[14.0, 3.7]}, {Around[466.5, 1.5],
Around[0.6, 0.7]}, {Around[502.5, 1.5],
Around[2.2, 1.5]}, {Around[520.5, 1.5],
Around[9.4, 3.1]}, {Around[538.5, 1.5],
Around[4.1, 2.0]}, {Around[646.5, 1.5],
Around[2.2, 1.5]}, {Around[682.5, 1.5], Around[0.6, 0.7]}}
Background:
This is the results of a radioactive decay experiment. These are points obtained from gaussian models (which is why they aren't integer), then points are then plotted and a model applied (the model is y=Ae^-(kt)), and then weighted for the uncertainties (weighting is 1/uncertainty^2). The target is then to find A (this is the y-intercept), k (this is the decay constant and will give the half-life, t = ln(2) / k). Half-life being the main desired figured (the time is takes for the decay curve to have reduced by half). Then produces the reduced chi^2 as a measure of a goodness of fit. And express this on a singular graphic, much as m_goldberg has done below.
Re-creating m_goldberg's answer:
Having copied the code across - it errors. I have tried to implement what I thought were fixes but unsuccessfully. I changed NonLinearModelfitData
to NonLinearModel[fitData,...]
, And on the very last line the Show
is not closed due to a missing speech mark after 'emission', so I added that in. But it outputs this:
uncertainties
? Without it being defined, your fit doesn't work and no one can see what is wrong with the rest of your code. $\endgroup$uncertainties = dataHist5[[All, 2, 2]];
But in practical terms, it's the error bars around each of the data points in dataHist5 $\endgroup$