Tag Info

New answers tagged

3

The maximum occurs at x = c1 and that value is a + yoff. So you can solve for the two values where the curve equals half of that maximum value assuming a > 0 and yoff > 0 (but only if (a+yoff)/2 >= yoff as otherwise there will be no intersection with the curve). a =.; b =.; c1 =.; yoff =.; sol = Solve[(a + yoff)/2 == a Exp[-(b (x - c1))^2] + yoff, ...


4

c1 = 1; yoff = .1; f[x_] := a Exp[-(b (x - c1))^2] + yoff d1 = Table[{x, f[x]} /. {a -> 2, b -> 3}, {x, 0, 4, .1}] nlm = NonlinearModelFit[d1, a Exp[-(b (x - c1))^2] + yoff, {a, b}, x] nlm["BestFitParameters"] {peakVal, peakPos} = FindMaximum[nlm[x0], x0] x1 = FindRoot[nlm[x] == 0.5*peakVal, {x, (x0 /. peakPos) + 0.05}] x2 = FindRoot[nlm[x] == ...


4

Intuition is sometimes tricky on fitting procedures. This is of course not a Mathematica issue, but a problem of fitting in general. You can see the problem in parameter space (hence it depends on the details of parameter space). Defining for the residuals (square root) Res1[ff_, aa_, bb_] := Norm[data[[All, 2]] - (m1 /. {f -> ff, a -> aa, b -> ...


5

If you want to force the piecewise function to be continuous at the breakpoints, then you must enforce that in your model. This takes away one parameter from your model, namely the a0 parameter Solve[a1*Erf[b1*(x - 15.99999)^c1] == a0 + b0*x /. x -> 27, a0] (* {{a0 -> -1. (27. b0 - 1. a1 Erf[11.^c1 b1])}} *) Plug this back in, fitModTot[x_] ...


9

Simple, just change your model so that continuity is guaranteed: fitModTot[x_] := Piecewise[ {{const, 10 <= x < 16}, {a1*Erf[b1*(x - 15.99999)^c1], 16 <= x <= 27}, {a1*Erf[b1*(27 - 15.99999)^c1] + b0 (x - 27), x > 27} }] a0 isn't necessary anymore: fit = NonlinearModelFit[ data, fitModTot[x], {const, ...


8

A few considerations: Are you sure that you want Erf there and not just Exp? Your argument to Erf in the Piecewise function seems to suggest that you are trying to set up an "exponential rise to max" model. Your data seems to be better fit when Exp is swapped in for Erf, using your same arguments. I guess that the 15.99999 value in your Piecewise ...


0

You've learned a valuable lesson... pesky things those "densities" - they aren't born in isolation but together with the "measure" they are defined with so the whole mathematical object becomes invariant. "Moral of story: Transforming densities is always like a "change of variables" when integrating!


3

Following Szabolcs advice, it seems that the Documentation page for EvaluationMonitor contains all what you need for Method -> "Newton": data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}}; Clear[evalCount]; evalCount[_] = 0; nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, EvaluationMonitor :> ++evalCount["Function"], Gradient ...


1

I have now figured out the issue. It was because I was not including a Jacobian term in the likelihood $\frac{dW}{dZ}=\frac{Z^{1/\beta-1}}{\beta}$. After doing so, the log-likelihood becomes: $l = -(n/2)ln(2\pi) - (n/2)ln(\sigma^2) - n ln(\beta) + (1/\beta-1)\sum ln(Z) - (1/{2\sigma^2})\sum_{i=1}^n (Z_t^{1/\beta} - \rho Z_{t-1}^{1\beta} - (1-\rho) ...


4

By removing the restrictions in the parameters things work fine (and much faster than leaving them in). In this case the resulting solution satisfies the restrictions so there's not reason to include them. However, because of the way you've written your function there are some warning messages (which I'm sure that very experienced Mathematica users can ...


0

After trying many ways to fit the -numerically solved- model described above, with lots of help from fellows, it turned out that -for this kind of model at least- fitting is much faster if ParametricNDSolve is used, instead of NDSolve, to solve the ODEs of the model. This is just what 'Guess who it is' slightly suggested in a comment to my original question. ...


2

So following @Szabolcs advice, {nl,ncounts}=Block[{c = 0}, {NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, Method -> "Newton", EvaluationMonitor :> c++], c}] or (doing something slightly different) counting the number of Log Calls. Trace[nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, Method-> ...


1

The interpolateCurve function gives the interpolation of curves. Options[interpolateCurve] = Join[Options[ParametricPlot3D], Options[Interpolation]]; interpolateCurve[pts : {{_, _} ..}, opts : OptionsPattern[]] := Module[{order, x, y, s, func1, func2}, order = OptionValue[InterpolationOrder]; x = pts[[All, 1]]; y = pts[[All, 2]]; ...


4

see comment below by OleskandrR If he posts I will up vote. Original post This is not ideal (and done with little time) but may motivate better answers. Note this manually (visually tries to minimize the discontinuity at "breakpoint") using Manipulate. The NonlinearModelFit treats the breakpoint as fixed so you can play and chose better way. I look forward ...


1

As I find your expressions difficult to work with, let me rewrite them somewhat: Clear[modelo]; modelo[k1_?NumberQ, ki1_?NumberQ, k2_?NumberQ, ki2_?NumberQ, k3_?NumberQ, ki3_?NumberQ, aR_?NumberQ, aRH1_?NumberQ, aRH2_?NumberQ, aRH3_?NumberQ, Ht_?NumberQ, Rt_?NumberQ] := modelo[k1, ki1, k2, ki2, k3, ki3, aR, aRH1, aRH2, aRH3, Ht, Rt] = ...



Top 50 recent answers are included