# Tag Info

14

[I gave a similar response some time ago either in StackOverflow or MSE but now I cannot find it.] One way is to track the solution to the ODE that runs over the difference if[x]-g[x]. Use WhenEvent to record axis crossings. This will find all zeros that do not have multiplicity (that is, that cross transversally). Should also find any that are of odd ...

12

I think as much discussion as can reasonably be had on this issue has already taken place on this site, although the solution might not be readily apparent without the benefit of experience. This is not in any way meant as a criticism of the question (which is well-posed and relates to a commonly-encountered, important issue), but rather will be my excuse ...

6

This is quite common a problem when doing nonlinear fit. As far as I know, the most general and effective solution for it is to give the fitted parameters a good enough start value, which you've already known for your specific problem: exp = c/(1 + ((c - n)/n)*E^(-r*t)); FindFit[points, exp, {{c, 256}, {n, 9}, r}, t] Show[Plot[exp /. %, {t, 7, 84}], ...

6

It seems that one way to accomplish separate coefficients for $\cos$ and $\sin$ is to define something like: bothfit = Fit[list, Flatten[Table[{Cos[n*x], Sin[n*x]}, {n, 0, end}]], x]; where I use Flatten to flatten out the Table before the Fit. I get this result: Grid[ Table[ bothfit = Fit[list, Flatten[Table[{Cos[n*x], Sin[n*x]}, {n, 0, end}]], ...

6

Here is a method that works with your example : First, one plots the two functions with a special mesh : f[x_] := 2 (x - 1) (x - 1.5) (x - .5) (x + .5) (x + 1) (x + 1.5); g[x_] := 0.4 x - 0.4; points = Table[{x, f[x]}, {x, -1.5, 1.5, .25}]; if = Interpolation[points]; graphic = Plot[Evaluate[{if[x], g[x]}], {x, -1.5, 1.52}, Mesh -> {{0.}}, ...

4

If "diagnostics" or standard errors are required you can use NonlinearModelFit with the starting values: fun = c n/(n + (c - n) Exp[-r t]); nlm = NonlinearModelFit[points, fun, {{c, 256}, {n, 9}, r}, t] Visualizing fit: Show[ListPlot[points], Plot[nlm[t], {t, 0, 90}]] You can get model: nlm//Normal yielding 3213.19/(12.3092 + 248.73 E^(-0.0877072 ...

3

It is equivalent to minimize the absolute values. This can be set up as an explicit linear programming problem. The advantage over the approach of @bobthechemist (which is good, and I voted up) is that the problem can then be shipped to special case LP code. vars = Array[x, d2]; linearexprs = mat.vars - vec; constraints = Join[Thread[max >= ...

3

As Stephen Luttrell has been pointed in the comments, the problem is that FindFit is not guaranteed to find a globally optimal fit in the nonlinear case. This is a property it shares with the similarly named functions FindRoot and FindMinimum. However, instead of imposing constraints, I would recommend just giving the algorithm a better starting point from ...

3

I take it that the essential question is how to solve an equation in which a term involves an InterpolatingFunction. If it is merely to plot the points, then I would use andre's method. Otherwise, I would use an approach like Daniel Lichtblau's with a small modification. The rest of this is essentially an extended comment to Daniel's answer and ...

2

Another variation.. Here I'm using Plot's automatic incrementation to trace out a sufficiently smooth set of points, then feeding zero crossings as initial points into FindRoot.. x /. FindRoot[if[x] - g[x], {x, #[[1, 1]], #[[2, 1]]}] & /@ Select[ Partition[ Sort@Last@Last@Reap[ Plot[if[x] - g[x], {x, ...

2

For what it's worth, replacing Erf with ArcTan gives a better result for this particular example. sol = a ArcTan[b (x - c)] + d /. FindFit[l, a ArcTan[b (x - c)] + d, {a, b, c, d}, x] (* 17.3813 - 13.6427 ArcTan[0.139271 (-60.7409 + x)] *) Then we can plot Show[ ListLinePlot[l], Plot[sol, {x, 1, Length[l]}, PlotStyle -> ColorData[1][2]] ] We ...

2

As Szabolcs writes in his comment: use NonlinearFit. data = { {0.473, 1.1}, {0.4825, 1.15}, {0.492833333333333, 1.2}, {0.503666666666667, 1.25}, {0.513666666666667, 1.3}, {0.5245, 1.35}, {0.533, 1.4}, {0.543166666666667, 1.45} }; model = NonlinearModelFit[data, a x^b, {a, b}, x] FittedModel[4.84687 x^1.97633] NonlinearModelFit returns a fitted ...

2

After patching your data and fixing/adjusting code (removed unneeded Total, upped samples): theta = data[[All, 1]]; w = data[[All, 2]]; num = Dimensions[theta][[1]]; n = 150; m = Table[ Flatten[Table[{Sin[i1*theta[[i2]]], 0}, {i1, 1, n}]] + Flatten[Table[{0, Cos[i1*theta[[i2]]]}, {i1, 1, n}]], {i2, 1, num}]; x = LeastSquares[m, w]; f[t_] := ...

2

If you avoid the intermediate integration of Ef1, you can do it all at once: eqnBo = D[Eb1[r, t], t] - (Ef1[r, t]) * (((p[r, t])/(p[r, t] + kmn)) * ((kme)/(kme + p[r, t])) + (1 - (p[r, t])/(kmn + p[r, t]))*j); x = ParametricNDSolve[{eqnBo == 0, Eb1[r, 0] == 0, eqnDe == 0, Ef1[r, 0] == 0, Derivative[1, 0][Ef1][micron, t] == 0, Ef1[ro, ...

1

Since LeastSquares can be written as NMinimize[Plus @@ ((mat.{x1, x2, x3, x4} - vec)^2), {x1, x2, x3, x4}] Then you can use a similar approach to minimizing your desired function: NMinimize[Max @@ ((mat.{x1, x2, x3, x4} - vec)^2), {x1, x2, x3, x4}] Although whether or not this is the "best" way is likely up for debate.

1

There a number of approaches. This is a start (amplifying Kuba's comment): lm = LinearModelFit[Log10@calibdata, {1, x}, x]; param = lm["ParameterTableEntries"] coeff = First@Transpose@param fun[x_] := 10^#1 x^#2 &@@ coeff The parameters: {{4.6208, 0.0963769, 47.945, 0.0132762}, {0.501766, 0.046298, 10.8378, 0.0585751}} Note the linear ...

1

calibdata = {{1, 39270.4}, {0.01, 4982.57}, {0.001, 1153.55}}; fit = LinearModelFit[Log10@calibdata, x, x]; % // Normal 4.6208 + 0.501766 x Plot[Normal@fit, {x, -4, 1}, Axes -> False, Frame -> True, Epilog -> {PointSize@.02, Point@Log10@calibdata}]

1

The RootSearch package http://library.wolfram.com/infocenter/MathSource/4482/ by Ted Ersek returns all the roots over a specified range as a list of replacement rules. A RootsInRange function was presented in "Finding Roots in an Interval" in The Mathematica Journal 7(2), 1998 (http://www.mathematica-journal.com/issue/v7i2/ updated code below): f[x_] := 2 ...

Only top voted, non community-wiki answers of a minimum length are eligible