Tag Info

New answers tagged

1

It is not clear to me what is the difference between FindFit and NonlinearModelFit. But NonlinearModelFit help says: And FindFit says In this case, they both indeed produce the same fit, hence both are doing least squares model = a + b/(c*x^2); nlm = NonlinearModelFit[data, model, {a, b, c}, x]; nlm["ParameterTable"] nml2 = FindFit[data, model, ...


1

Here is how I would do it. First, import the data using Import. This is straightforward from the documentation, using either Excel or txt files, so for the purposes of this exercise, I'm going to generate the data in Mathematica instead. myD = MixtureDistribution[{2, 1}, {NormalDistribution[2, 2], NormalDistribution[2, 1/2]}]; For reference, here is ...


0

Well I have done this in that way: calcMethod[randFN_, randfacdef_, samplerun_] := Module[{limit, vmaxmod, kmmod, yy0, xx, yy, data, datalb, dataeh, datahw, minxlb, maxxlb, minylb, maxylb, minx, miny, maxx, maxy, minxeh, minyeh, maxxeh, maxyeh, minxhw, maxxhw, minyhw, maxyhw, vmaxnl, kmnl, vmaxlb, kmlb, vmaxeh, kmeh, vmaxhw, kmhw, mmenten, eadieh, ...


1

Use the Check[] function to handle exceptions that throw messages. In detail, however, I would say that the problem is not well defined.


1

Only last line in Module can be used for output (I mean without ';'). So put semicolon after EACH line except last one, the Print command will work anyway. Then it will work - just tested


7

NMinimize[] with the Automatic method works nice ... sometimes. You can help it by providing a better choice. Like in: ts1 = {{682, 98}, {739, 165}, {784, 286}, {826, 470}, {850, 618}, {871, 779}}; ts2 = {{683, 92}, {739, 174}, {785, 299}, {827, 489}, {851, 637}, {871, 807}}; tt = {ts1, ts2}; nlm = NonlinearModelFit[#, a Exp[b t];, {a, b}, t, ...


7

Easier by using ParametricNDSolve[]: params = {γ, a, b}; model = x /. ParametricNDSolve[{x''[t] + γ x'[t] + a x[t] + b x[t]^3 == 0, x[0] == 2, x'[0] == 0}, x, {t, 0, 20}, params]; fit = FindFit[data, model[Sequence @@ params][x], params, x, PrecisionGoal -> 4, AccuracyGoal -> 4] (* {γ -> 0.339787, a -> ...


4

The requirement that la + lc == 100 is simple to implement, just pass 100 - la to Fc, or use ModelP/.{lc->100-la} in the call to FindFit. For the other trouble, remember that N is a special function in Mathematica, so avoid ever using this as a variable. Using n instead, I tried ModelP = (2/q^4)*Re[((1 - Fc[q, lc, sc])*(1 - Fa[q, la, sa]))/ (1 - ...


18

vars = {w, x, y, z}; terms = MonomialList[(Plus @@ vars)^3] /. _Integer x_ :> x; cols = Join @@ {vars, terms} (* {w,x,y,z,w^3,w^2 x,w^2 y,w^2 z,w x^2,w x y,w x z,w y^2, w y z,w z^2,x^3,x^2 y,x^2 z,x y^2,x y z,x z^2,y^3,y^2 z,y z^2,z^3} *) For the data dt = Table[Join[RandomInteger[10, 4], {RandomReal[]}], {100}]; evaluate all models with up to ...


3

Here is an approach using linear regression: circfit[data_] := Module[{reg, lm, bf, exp, center, rad}, reg = {2 #1, 2 #2, #2^2 + #1^2} & @@@ pts; lm = LinearModelFit[reg, {1, x, y}, {x, y}]; bf = lm["BestFitParameters"]; exp = (x - #2)^2 + (y - #3)^2 - #1 - #2^2 - #3^2 & @@ bf; {center, rad} = {{#2, #3}, Sqrt[#2^2 + #3^2 + #1]} & @@ ...


11

data = Table[{i, i}, {i, 10}]; model = a + b x ^2; Unrestricted model: nlm = NonlinearModelFit[data, model, {a, b}, x] // Normal $ 0.0863422 x^2+2.17582 $ Model restricted to pass through {5,5}: nlmr = NonlinearModelFit[data, {model, (model /. x -> 5 ) == 5}, {a, b}, x] // Normal $ 0.0790502 x^2+3.02375 $ Picture: Show[Plot[{nlm, ...


1

data = {{0, 1}, {1, 0.05}, {3, 2}, {5, 4}}; lm = LinearModelFit[data, x, x]; You can also use Transpose[{data[[All, 1]], lm["FitResiduals"]/data[[All, 2]]}] (* {{0, 0.791525}, {1, -16.9831}, {3, -0.140254}, {5, 0.0845339}} *) or Transpose[{First@#, lm["FitResiduals"]/Last@#} &@Transpose[data]] (* {{0, 0.791525}, {1, -16.9831}, {3, -0.140254}, {5, ...


2

In addition to correcting the syntax errors, having some approaching to starting values of parameters will help get desired fit, e.g. (using the definition from Nasser's correction of syntax errors and the data) Manipulate[ Plot[f /. s -> p, {L0, 20, 70}, Epilog -> Point@data], {p, 20, 40}] so fitting: nlm = NonlinearModelFit[data, {f, s > ...


1

syntax errors and not good choice of l as variable name as it looks like 1. Also need a constraint added to avoid complex values errors Clear[s, L0]; data = {{45.65, 38.9}, {66.87, 47.7}, {79.65, 63.4}, {36.03, 25.81}, {64.79, 71.99}}; f = (180/Pi)*ArcCos [-1 + (2*(s/L0)^0.5)*(Exp[-0.0001247 (L0 - s)^2])]; model = NonlinearModelFit[data, {f, s > 0}, ...


3

You may do it with Interpolation[] by expanding the list with a parameter value: l = {{0, 0}, {1, 0}, {.5, 1}, {-1, -2}, {1, 3}}; f = Interpolation[Table[{i, l[[i]]}, {i, Length@l}], InterpolationOrder -> #] & /@ {3, 4}; Row[ParametricPlot[f[[#]][t], {t, 1, Length@l}, Epilog -> {Red, PointSize[Medium], Point@l}, AspectRatio ...


5

Well, you have two questions in one: (1) How to "take" the curve from the image into Mma? and (2) How to fit it?. Here I address the first question and give one possible solution aditional to the ones offered before. Some time ago I published a function copyCurve on this site, along with its detailed description. You can take it from there. Copy the ...


3

Here's something to get you started, (assembled from Andy Ross' code). Data points are extracted from a data series in an image. Your original image will need some editing in order to process each curve separately. The following tadpoles plot is used for example. img = Import@"http://www.biologycorner.com/resources/graph_tadpoles.JPG"; data = ...


2

Try this: Show[{ ListPlot[Log10@data], Plot[Normal[H], {x, 23, 26}] }] Have fun!


0

One more try: relations = SolveAlways[(b1 x + b2 x)/(b3 + (b4/b5) x) == (c1 x)/(c2 + c3 x), {x}][[4]] {b3 -> ((b1 + b2) c2)/c1, b4 -> ((b1 + b2) b5 c3)/c1} This gives nontrivial relations between parameters you should always keep for any x. Convert them to equations and remove some freedom restrictions = Equal @@@ relations; myChoice = ...


1

After fixing the many typos you have (what is log? Mathematica uses Log), and adding a constraint on k else complex solution will result, here it is data = {{0.617, 0.8}, {0.605, 0.6}, {0.5997, 0.4}, {0.5972, 0.2}, {0.5985, 0.1}}; soln = NonlinearModelFit[data, {y - 2478.82*w Log[k c + 1], k > 0}, {y, w, k}, c, MaxIterations -> 1000] There ...



Top 50 recent answers are included