I am trying to manipulate a data set and view a dynamically updating plot of the nonlinearmodel fit of the data. The comments in the example code below show the two things that work (manipulating a listplot of the data, and plotting a nonlinearmodel fit) and my attempt to be able to manipulate the data set that generates the nonlinearmodel fit.
data = ImportString["\t16\t13\t9\t6
600\t2.36\t2.34\t2.31\t2.27
592\t2.68\t2.61\t2.55\t2.45
584\t3.66\t3.41\t3.21\t2.93
576\t4.58\t4.11\t3.81\t3.33
568\t3.91\t3.61\t3.39\t3.05
560\t3.62\t3.38\t3.19\t2.91
552\t3.91\t3.61\t3.38\t3.04
544\t4.41\t4.01\t3.72\t3.27
536\t4.31\t3.93\t3.65\t3.23
528\t3.75\t3.48\t3.28\t2.98
520\t3.27\t3.09\t2.96\t2.75
512\t3.10\t2.96\t2.85\t2.67
504\t3.11\t2.97\t2.85\t2.68
496\t3.17\t3.01\t2.89\t2.71
488\t3.25\t3.08\t2.95\t2.75
480\t3.37\t3.17\t3.03\t2.82
472\t3.56\t3.32\t3.16\t2.91
464\t3.83\t3.55\t3.35\t3.04
456\t4.25\t3.89\t3.63\t3.24
448\t4.84\t4.47\t4.09\t3.55
440\t5.70\t5.52\t4.87\t4.11
432\t10.00\t5.72\t6.10\t5.13
424\t10.00\t6.18\t5.79\t5.43
416\t10.00\t5.63\t5.87\t5.72
408\t10.00\t6.21\t5.73\t5.54
400\t10.00\t6.19\t5.44\t5.47", "TSV"];
xValues = {16, 13, 9, 6};
(*This works to manipulate the data set and plot the individual \
points*)
Manipulate[
ListPlot[{Partition[Riffle[xValues, Drop[data[[Upper]], 1]],
2]}], {{Upper, 10}, 1, 26, 8}]
(*This works to create & plot a fit for a certain set of data*)
nlm = NonlinearModelFit[
Partition[Riffle[xValues, Drop[data[[10]], 1]], 2], a*x^b, {a, b},
x];
Plot[nlm[x], {x, 0, 20}]
(*This does NOT work to create & plot a fit for a manipulated set of \
data*)
Manipulate[
Plot[NonlinearModelFit[
Partition[Riffle[xValues, Drop[data[[Upper]], 1]], 2],
a*x^b, {a, b}, x][x], {x, 0, 20}], {{Upper, 10}, 1, 26, 8}]
The final Manipulate command gives the errors:
General::ivar: 0.0004085714285714286` is not a valid variable. >>
General::ivar: 0.0004085714285714286` is not a valid variable. >>
General::ivar: 0.0004085714285714286` is not a valid variable. >>
General::stop: Further output of General::ivar will be suppressed during this calculation. >>
Any suggestions? Thank you!
xin theNonLinearModelFitgets replaced by thexfromPlot. Try putting anEvaluateto pre-emptPlot. i.e.Evaluate@NonlinearModelFit[...][x]. – b3m2a1 Sep 19 '17 at 23:36Evaluated -> TruetoPlot. – Karsten7 Sep 19 '17 at 23:44