Tag Info

Hot answers tagged

9

I think what you're seeing is a consequence of the special model that you're using. The parameters a and b appear only linearly, so as long as they are the only fit parameters it is clear that the best approach for FindFit would be to perform a simple LeastSquares calculation. This is a matrix method that works over the complex numbers, and that's why you ...


6

For the reason why find fit fails when c is variable, please see the answer of Jens. One way to solve this is to use create the complex target function from real-valued parameters and set the NormFunction explicitely: f1[t_] := (br + I bi) + (ar + I ai)/(cr + I ci + t) fit = FindFit[data, f1[t], {ar, ai, br, bi, cr, ci}, t, NormFunction -> ...


6

You can try to implicitize, sort of. I do this step by step so we can see what substitutions are needed. exprs = ExpToTrig[ Expand[Simplify[ Chop[ComplexExpand[{Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I 2.36121) Exp[(0.455 + I 1.099) t] + (-2.35438 + I 1.36651) Exp[(0.455 - I 1.099) t] ...


5

Your model function isn't allowing for a better fit. Are you sure that the model is correct? Below is a plot using a different model which allows to find better start values for a fit. Mind you I haven't done a fit. Show[ListPlot[Re[data]], Plot[Re[b + a/((-1.028 + 0.0492 I) + s)] /. {a -> -0.248 - 0.306 I, b -> -0.403 + 0.106 I}, {s, 0.45, ...


5

The coordinates of the parametric curve consist of the solution of a fourth-order linear differential equation and its derivative. This is clear by inspection. First, we need the x coordinate in a form that can be differentiated: xOP = Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I 2.36121) Exp[(0.455 + I 1.099) t] + (-2.35438 ...


4

@rcollyer's answer is 100% correct, though it is telling that the ListLogLinearPlot of your data follows a polynomial shape. This tells me that your y-values follows a polynomial function with your Log[x] values. The plots seem to confirm this, as the curve fits your data much better: Clear[ExpDataCyclesMpa, LeastSqr] ExpDataCyclesMpa = ...


4

fit = FindFit[data, model, {a, k}, t, Method -> "NMinimize"]


4

My answer below is mostly inspired by the answers of @Matariki and @george2079, so thank you both for your efforts and insight. I also got some ideas (about minimizing least square) from here (warning: it's a Matlab SO). My approach is to minimize the least square errors/residuals/differences between the data and the fit function in terms of both real and ...


4

I've done this from first principles: some random data: data = Table[{x + RandomReal[{-.05, .05}] + 4, Sin[x] + Sin[x/3] + RandomReal[{-.3, .3}]}, {x, 0, 12 Pi , .1}]; treat the discrete data as a function and and use trapezoidal integration: trule = Mean /@ Partition[ Differences@ {data[[1, 1]], ...


3

As has been already commented you can specify Method or specify approximate parameter values as per Rahul Narain's comment. You can also use NonlinearModelFit,e.g.: nlm=NonlinearModelFit[data, {a Exp[- k t]}, {{a, 53000}, {k, 1/100}}, t] yields :448761. E^(-0.0128453 t) Visualizing fit: Plot[nlm[t], {t, 80, 200}, Epilog -> {Red, PointSize[0.02], ...


3

If you fit the real part of the data directly: FindFit[ Re[data] , Re[b + a/((-0.977727 + 0.0601085 I) + s)] , {{a, -.1}, {b, -.1}}, s] {a -> -0.0791299, b -> -0.121803} Gives a pretty good fit, and surprisingly not too bad in the complex part either. Better ... <-- not.. This explicitly does the least squares minimization over ...


2

I don't think there is anything unusual here that can't be found in the documentation. Normalization parameters in the x and y dimensions (b, and a, respectively) can be added into the model, as can the x-axis shift (parameter c). Parameter estimates are taken from a look at the original data. nlm = NonlinearModelFit[data, a Erfc[b (x + c)], {{a, 8 ...


2

I am a little unsure what the aim is here. Looking at the data only the first third of the plot could be fitted to Erfc like function. I post this, perhaps, as motivation. d = Transpose@data; ListPlot[ds = SortBy[d, #[[1]] &], Joined -> True] Extracting the part of plot I referred to: fd = ds[[1 ;; 35]] fdlp = ListPlot[fd] Now as a rather ...


2

This maybe not an efficient way of doing this problem, but here is my approach: First you need to convert the parametric data into polar data. my way of doing this is as follows ( I don't know any better way to convert data from {x,y} to {t,r}): data = Table[{Im[(4.85263 + I 1.15883) Exp[(-0.455 + I 1.099) t] + (-2.21527 + I ...


2

You may be interested to know that we are working on a FindSimpleFit function that is intended to automate the finding of many common classes of curve, exponentials obviously included. This is similar to what Wolfram|Alpha Pro currently does when you upload a dataset that looks like a timeseries or scatterplot. Automation for the win!


2

I took george2079's statement "Now I expect someone will show a built-in way to get this..." as a challenge, so I did the same thing using FindFit. Also, writing it this way seems more clear to me what the actual function being fitted is (but obviously relying on the internal FindFit function) len = (Max[#] - Min[#]) &@data[[All, 1]]; func = ...


1

An Alternative: a = Transpose[{ExpDataCycles, ExpDataMpa}]; b = Interpolation[a, InterpolationOrder -> 2]; c = LogLinearPlot[b[x], {x, 6., 10^6.}, GridLines -> Automatic]; d = ListLogLinearPlot[a, PlotStyle -> Red]; Show[c, d, PlotRange -> All, ImageSize -> 400]


1

Use LogLinearPlot, instead: ExpDataCyclesMpa = Transpose[{ExpDataCycles, ExpDataMpa}]; LeastSqr = Fit[ExpDataCyclesMpa, {1, x, x^2}, x]; Show[ListLogLinearPlot[Transpose[{ExpDataCycles, ExpDataMpa}]], LogLinearPlot[LeastSqr, {x, 1, 1100000}]]


1

Searching the documentation for FitResiduals leads directly to LinearModelFit and NonlinearModelFit, where it is stated that "FitResiduals" -- difference between actual and predicted responses For example, pts = Table[{x, x + RandomReal[.1 {-1, 1}]}, {x, 0, 5, .2}]; fm = LinearModelFit[pts, x, x] Now fm["FitResiduals"] is the same as #2 - ...


1

One way to do this is to take the log of the data, and do a linear fit: fit = FindFit[ Transpose@{Log@ExpDatN, ExpDatMPa} , a + b ln , {a, b}, ln ] or fit to the log expression: fit=FindFit[ Transpose@{ExpDatN, ExpDatMPa} , a + b Log[n] , {a, b}, n ] (same result) Show[{ListLogLinearPlot[{Transpose[{ExpDatN, ExpDatMPa}]}, ...


1

The problem is that you specify a parametric function with 4 arguments (*{kme, kmn, j, eo}*) but only feed the function call two. You'd need to set the proper parameters but then this will work: x = ParametricNDSolveValue[{eqnBo == 0, Eb1[r, 0] == 0, eqnDe == 0, Ef1[r, 0] == 0, Derivative[1, 0][Ef1][rn, t] == 0, Ef1[ro, t] == eo}, Eb1, {r, ...


1

p1 = Histogram[data, {0, 9, 1}, "Count", ChartLegends -> {"Experimental Result"}, ChartStyle -> "Pastel"]; p2 = DiscretePlot[ Length@data*PDF[PoissonDistribution[2.2766917293233084`], x], {x, 0, 10}, PlotStyle -> {Red, Medium}, PlotLegends -> {"Theoretical Poisson"}]; Show[{p1, p2}, AxesLabel -> {"Time (s)", "Counts"}] ...


1

I've noticed that sometimes I get some small imaginary components due to error etc. You may want to use the Chop[] function to kill anything like that.


1

You might want to limit "shift" to positive only? Otherwise your function can be complex? I am guessing the value of "shift" Mathematica obtained from FindFit is negative.



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