0
$\begingroup$

I tried to fit my data (see bellow) with the following code. It works but I get the following message :

NonlinearModelFit::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations.

I changed the number of iteration from 100 to 200 or more using MaxIterations but style have the problem. So I am not sure about the accurancy of my fit...even if it works.

data = Import["https://pastebin.com/raw/ADajyTYF", "TSV"]

(* data = ReadList[file, Number, RecordLists -> True]; *)
dataT = Transpose[data];
dataT = {10*dataT[[1]], dataT[[2]]};
error = Transpose[data][[3]];
data = Transpose[dataT];
nmax = Length[data];

mu0 := 4*Pi*10^(-7);
Ms := 3.41;                                                           \

DD:=    2*10^(-3)          \
lM = 10^9*Sqrt[2*A*mu0/Ms^2]
lD[DD_] := 10^9*2*DD*mu0/Ms^2
lD[0.003]
h2[Hp_, q_, RH_] := Hp^2/(1 + q^2*RH^2)^2
Heff[q_, H_, A_] := H + 2*A/(Ms/mu0)*q^2*10^(18)               
p[q_, H_, A_] := Ms/Heff[q, H, A]                                                                 \

nenner[q_, H_, DD_, A_] := 1 - p[q, H, A]^2*lD[DD]^2*q^2
chi[Hp_, q_, H_, DD_, RH_, A_] := (4*p[q, H, A]^3*h2[Hp, q, RH]*lD[DD]*q)/nenner[q, H, DD, A]^2 

singlefit2 = 
  NonlinearModelFit[data, 
   chi[Hp, q, 5, DD, RH, 
    A], {{Hp, 2000}, {DD, 0.001}, {RH, 15}, {A, 10*10^(-12)}}, q,
       Weights -> error, MaxIterations -> 100];

singlefit2["BestFitParameters"];
singlefit2["EstimatedVariance"];
singlefit2["ParameterErrors"];
singlefit2["ParameterConfidenceIntervals"];
MatrixForm[singlefit2["CorrelationMatrix"]];
Print[singlefit2["ParameterTable"]];
$\endgroup$
  • $\begingroup$ I can't access your dataset from the link you provided $\endgroup$ – Fraccalo Jun 21 '18 at 7:44
  • $\begingroup$ It should be fine now. $\endgroup$ – Bigprophete Jun 21 '18 at 7:51
  • 1
    $\begingroup$ What are Ms, mu0, h2, and lD? $\endgroup$ – JimB Jun 21 '18 at 14:57
  • $\begingroup$ They are constant parameters. $\endgroup$ – Bigprophete Jun 21 '18 at 15:44
  • $\begingroup$ I changed your link to your data to a permanent repository easy to Import from. You should include any clarification in your question (please edit). Also give typical values for your constant parameters, we can't reproduce your problem without that. If you expect to inspire anybody to volunteer their time to look at your problem, then you should help us as much as possible. $\endgroup$ – rhermans Jun 21 '18 at 15:53
1
$\begingroup$

This is not an answer, but some hints.

  1. You set DD := 2*10^(-3), but in NonlinearModelFit you want to use it as a parameter.
  2. You define lM = 10^9*Sqrt[2*A*mu0/Ms^2] , but never use it.
  3. The starting parameter seem to be not good. Try to find better one with

    Manipulate[ LogPlot[chi[Hp, q, 5, DD, RH, A], {q, 0, 1.2}, PlotRange -> All, Epilog -> Point[data]], {{Hp, 2000}, 0, 2000}, {{DD, 10^-3}, 10^-4, 10^-1}, {{RH, 15}, 0, 30}, {{A, 10^-11}, 10^-16, 10^-10}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for your comments and will try to do that ;) $\endgroup$ – Bigprophete Jun 22 '18 at 7:46
  • $\begingroup$ Using manipulate, I can find good approximations parameters but when I put as initial parameters in code as initial parameters, then I get the following message : NonlinearModelFit::sszero: The step size in the search has become less than the tolerance prescribed by the PrecisionGoal option, but the gradient is larger than the tolerance specified by the AccuracyGoal option. There is a possibility that the method has stalled at a point that is not a local minimum. $\endgroup$ – Bigprophete Jun 25 '18 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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