0
$\begingroup$

We have a list :

mainlist={ {1.*10^-6, 0.496422}, {0.000011, 
  0.487914}, {0.000021, 0.483133}, {0.000031, 0.479348}, {0.000041, 
 0.476095}, {0.000051, 0.473187}, {0.000061, 0.470526}, {0.000071, 
 0.468053}, {0.000081, 0.46573},{0.0001, 0.461636}, {0.0002, 0.444089}, 
 {0.0003, 0.429989}, {0.0004,0.417684}, {0.0005, 0.406535}};

We have exploited

fitting=NonlinearModelFit[mainlist, 0.5 - b g^0.5, {a, b}, g];

Mathematica gave us 0.5-4.01902*g^0.5. We can plot mainlist and fitting in one plot

listplot = ListPlot[mainlist, PlotRange -> {{0, 0.005}, All}];
plot=Plot[0.5-4.01909 g^0.5,{g,0,0.005}];
Show[{plot,listplot}]

enter image description here

But, the desired case for us is a linear show.

In fact, however we know that the fitting function is described by g^0.5, but we wish to have plot with linear form as (we don't understand how we do this job):

enter image description here

$\endgroup$
1
  • $\begingroup$ Maybe use ListLogPlot and LogPlot ? $\endgroup$ Jan 3, 2018 at 10:41

3 Answers 3

2
$\begingroup$

Your function is

$$y=0.5-bx^{1/2},$$

so

$$\log\frac{0.5-y}{b}=\frac{1}{2}\log x.$$

That means you need

nlm = NonlinearModelFit[mainlist, 0.5 - b g^0.5, b, g];
coeff = nlm["ParameterTableEntries"][[1, 1]];

data = {#[[1]], (0.5 - #[[2]])/coeff} & /@ mainlist;
plot1 = ListLogLogPlot[data, Frame -> True]

enter image description here

Then

plot2 = LogLogPlot[x^0.5, {x, $MachineEpsilon, 0.005}, Frame -> True, PlotStyle -> Red];
Show[plot1, plot2]

enter image description here

$\endgroup$
7
  • $\begingroup$ Thank you so much. But a surprising point: We have 14 pairs in mainlist. In interval [10^-6, 10^-4) we have 9 pairs. And for [10^-4, 5*10^-4] we have just 5 pairs. In the final plot the pairs in the mentioned intervals are not distributed correctly I think. $\endgroup$ Jan 3, 2018 at 18:32
  • $\begingroup$ For example: in [10^-6, 10^-4) we do not have 9 pairs in the plot! $\endgroup$ Jan 3, 2018 at 18:33
  • $\begingroup$ Do Log10@mainlist and see for yourself; I don't get your objection - that's how your data points are distributed. $\endgroup$
    – corey979
    Jan 3, 2018 at 18:35
  • $\begingroup$ I can understand. You are right. Your answer is correct. $\endgroup$ Jan 3, 2018 at 18:37
  • $\begingroup$ So sorry: A question: When you told Log(0.5-y)/coeff = 0.5 Log x in the second equation, but in ListLogLogPlot[data], the 0.5 coefficient before Log x will not be considered!! $\endgroup$ Jan 3, 2018 at 18:42
2
$\begingroup$

You can use Fit instead of NonlinearModelFit.

fit[x_] = Fit[mainlist, {1, x}, x] (*{1,x} as you are fitting a+bx*)
Plot[fit[x], {x, 0, 0.0005}, Epilog -> Point[mainlist]]

0.48385 - 167.767 x

enter image description here

$\endgroup$
2
$\begingroup$

If you want a linear plot, you'll need to plot $y$ vs $x$ with $x$ having a square root scale.

ListPlot[mainlist, ScalingFunctions -> {{#^0.5 &, #^2 &}, None},
 ImageSize -> Large, Frame -> True, 
 FrameTicks -> {{Automatic, None}, {{0, 0.1, 0.5, 1, 2, 3, 4, 5}/10000., None}}]

Plot of data with x on a square root scale

However, you might consider a more general curve because a fit with two additional parameters provides a much better fit.

fit1 = NonlinearModelFit[mainlist, 0.5 - b g^0.5, {b}, g];
fit2 = NonlinearModelFit[mainlist, a - b g^c, {a, b, c}, g];

The residual variance of fit2 is only 1.2% of fit1. The AIC value for fit2 is way smaller than for fit1. Theoretically the 0.5 values might be true but your data is saying something different. The 95% confidence interval for c does not include 0.5:

fit2["ParameterConfidenceIntervalTable"]

Confidence interval table

Here are the two residual plots:

ListPlot[{Transpose[{fit1["PredictedResponse"], fit1["FitResiduals"]}],
  Transpose[{fit2["PredictedResponse"], fit2["FitResiduals"]}]}, 
 Frame -> True, 
 FrameLabel -> (Style[#, Bold, 18] &) /@ {"Predicted response", 
    "Fit residuals"}, PlotLegends -> {"0.5-b g^0.5", "a-b g^c"}]

Residual plots

However, there's still a strong "pattern" to the residuals of the better fit which suggests there still something else going on:

ListPlot[Transpose[{fit2["PredictedResponse"], fit2["FitResiduals"]}],
  Frame -> True, 
 FrameLabel -> (Style[#, Bold, 18] &) /@ {"Predicted response", "Fit residuals"}]

Residual plot for better fitting model

$\endgroup$
1
  • $\begingroup$ Thanks a bunch for your clarified answer. I think it is why my fitting is not more correct than a-b g^c. $\endgroup$ Jan 3, 2018 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.