Tag Info

New answers tagged

0

Could be interpreted as a nonlinear least squares problem. pts = {{70.26, 45.78}, {71.04, 46.32}, {37.23, 24.67}, {37.91, 28.78}}; ndsoln[{k1_, k2_, k3_}, x0_] := x[720] /. NDSolve[{x'[t] == -k1 x[t]^2 + k2 x[t] y[t], y'[t] == k1 x[t]^2 - k2 x[t] y[t] - k3 y[t], x[0] == x0, y[0] == 0}, {x, y}, {t, 0, 720}][[1]] ssfun[{k1_?NumericQ, ...


0

If one absolutely insists on using LinearModelFit[] for linear detrending: model = LinearModelFit[data, x, x]; trendFree = Transpose[{data[[All, 1]], model["FitResiduals"] + model[0]}]; Otherwise, we can do something quite similar to Mr. Alpha's procedure: b = Last[LeastSquares[DesignMatrix[data, x, x], data[[All, 2]]]]; trendFree = data.{{1, -b}, {0, ...


1

Since you only want to remove the linear trend. Just use Fit, and this is also easy to understand.(And a little faster than Mr Alpha's on my computer.) data = RandomVariate[NormalDistribution[0, 50], {150000, 2}] + Range[150000]; AbsoluteTiming[ f[x_] = Fit[data, {1, x}, x]; ans=Transpose@{data[[;; , 1]], data[[;; , 2]] - f@data[[;; , 1]]};] ...


6

If all you want is to remove a linear trend from the data you don't need all the fancy statistics done by LinearModelFit and a faster alternative is to just use LeastSquares and then use the resulting parameters to remove the trend from the data. (*Generate 150k datapoints with a linear trend*) data = RandomVariate[NormalDistribution[0, 50], {150000, 2}] + ...


3

The syntax you are using is incorrect. Try model[{1,2,3}] and notice that it can't be applied to a list. Just change model[data[[All,1]]] to model /@ data[[All,1]]. This will finish in time, but it won't be fast at all (I do not know why). This will be much faster (in place of model /@ data[[All,1]]): model["BestFit"] /. x -> data[[All, 1]]


2

You can dynamically select the desired data range by using locators: data = Table[{x, x x }, {x, 0, 100}]; Manipulate[((p1 = Sort[p][[All, 1]]; lm = LinearModelFit[Select[data, (p1[[1]] < #[[1]] < p1[[2]] &)], x, x]; Show[ListPlot[data, PlotRange -> 10^4 {-1, 1}], Plot[lm[x], {x, 0, 100}, ...


5

As suggested by @b.gatessucks you can use Select. data = Table[{x, Sin[x] + RandomReal[{-0.5, 0.5}]}, {x, 0, 15, 0.25}]; pl = ListPlot[data]; ff = LinearModelFit[data, Sin[x], x] Show[pl, Plot[ff[x], {x, 0, 15}]]; and after selection over the range [2,8]: ff2 = LinearModelFit[Select[data, #[[1]] > 2 && #[[1]] < 8 &], Sin[x], x] Show[pl, ...


1

I think the issue is that your function U is defined only for integer r, whereas FindFit would want to sample the function at intermediate points as well. In this case, you can build the least squares by hand. Additionally, your choice seems to be a poor fit; the vector racc decreases with its index, which makes your U increase so you won't get a good fit. ...


2

Try FromDigits[] U[r_] := ecc (1 - (FromDigits[racc, r] - Exp[-Acc (1 - rscc)])^2);


7

As I pointed out in the comments. LinearModelFit was designed to make it easy to specify models fit using LeastSquares given some input data by providing a language for constructing design matrices via basis functions. LinearModelFit also aims to make the workflows of plotting models, computing residuals, parameter confidence intervals, etc much easier. ...


2

Plot automatically reduces the Plot range depending on the function that is plotted. Adding PlotRange->All shows the function completely in the Plot plot. Show uses the data range from the first plot that is shown, so you eventually need to add a PlotRange->All inside the Show command (depending on your data). modelFit = NonlinearModelFit[data, a*x^n, ...


1

Create some data: data = Map[Sin[# Range@100] + # &, {1, 5, 3, 6}] // N; Create some fits: fits = LinearModelFit[#, g, g] & /@ data; Plot the data: g1 = ListLogPlot[data, PlotRange -> {{0, 100}, Automatic}, Joined -> True]; Plot the fits: g2 = ListLinePlot[Log@Thread[#[Range[0, 100]]]& /@ fits, PlotRange->{{0, 100},Automatic}] ...


4

Sure. Try e.g. data = Transpose[{Range[10], Range[10]^3}] and then use NonlinearModelFit[data, x^n, {n}, x]. As bill s said, read for more details Mathematicas help regarding NonlinearModelFit. For your data you can use: fitFkt = NonlinearModelFit[data, a*x^n, {a, n}, x] fitFkt["ParameterConfidenceIntervalTable", ConfidenceLevel -> .95] The result is ...


2

If the model is linear, you can use LinearModelFit. If the model is nonlinear, then NonlinearModelFit. To see how to apply these, check out the help (F1 on the word LinearModelFit`) where there are plenty of examples. To mimic the function you've included, you could try something like: NonlinearModelFit[data, a + b x + c x^n, {a,b,c,n}, x]; Though it ...


5

You can use constraints together with the definition of your model function : rep2 = NonlinearModelFit[test, Join[{function[x]}, function[#[[1]]] <= #[[2]] & /@ test], {a, b, c}, x]; rep2 // Normal (* 120. - 45.6667 x + 5.33333 x^2 *) Show[ListLinePlot[test, PlotMarkers -> Automatic, AxesOrigin -> {0, 0}], ...


2

A simple penalty method is just to multiply the norm by some factor when the error is positive, e.g: rep = FindFit[test, function[x], {a, b, c}, {x}, NormFunction -> (Total[(20 Sign[#] + 21) #^2] &)]


3

Not having good starting values at hand, nor sufficient time to spare with your problem, here was the best I could do: {mv, am} = Quiet @ NMinimize[Norm[Norm[ Map[Function[x, With[{kx = First[#]}, CharacteristicPolynomial[H[kx], x]] // Evaluate], Rest[#]]] & /@ dat], {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ...


4

There are many ways to de-noise data. A simple one is to use one of the built-in filters. For example here I've applied the MeanFilter separately to the x and y dimensions of the data points that make up the arrows (i.e., your noisydata). This is sensible because your points lie on a regular grid. args = noisydata[[All, 1]]; datVals1 = ...


3

Here's a rather ad hoc procedure for logistic fitting that I use: dat = N[{{0, 15576}, {10, 15935}, {20, 16326}, {30, 18235}, {40, 21680}, {50, 22927}, {60, 28667}, {70, 41674}, {80, 50020}, {90, 75979}, {100, 148700}, {110, 197200}, {120, 212801}, {130, 215499}, {140, 227511}}]; (* rough estimate of asymptote *) c0 = Max[dat[[All, 2]]]; ...


5

I think you have to give some reasonable start values for the fit. E.g. try fitFkt = NonlinearModelFit[data,c/(1 + a Exp[-b x]), {a, {b, 0.1}, {c, Max[data[[All, 2]]]}}, x] As you can see from Show[ListPlot[data], Plot[fitFkt[x], {x, 0, 150}]], the fit is quite ok.



Top 50 recent answers are included