Message Boards Message Boards

0
|
4302 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Perform a non-linear fitting?

Posted 5 years ago

hi, i'm a new to the mathematica,need some advice on how i do a fitting to this kind of data,try to fitt to gaussian model but end up to nowhere,please anyone can give me a suggestion on how i suppose to to a fitting,tq

data4 = {{1, 0.7908237678805172`}, {2, 0.7923540508123751`}, {3, 0.79741355834688`}, {4, 0.8075308378102534`}, {5,  0.82630159208019`}, {6, 0.8617959376912471`}, {6.5`,0.9311495289477106`}, {6.75`, 0.9858878062075014`}, {7, 
    1.0183233500654116`}, {7.5`, 1.052535900411738`}, {7.75`, 
    1.1139261047524773`}, {7.85`, 1.1322647992772223`}, {8, 
    1.1359323690995655`}, {8.25`, 1.1370214756148385`}, {9, 
    1.1271031295853728`}, {10, 1.0397067038571146`}, {11, 
    0.9209408678283771`}, {12, 0.854055093889399`}, {13, 
    0.8189527427776097`}, {14, 0.7993224779484722`}, {15, 
    0.7874811068946352`}, {16, 0.7798540751147963`}, {17, 
    0.7709924536766344`}, {18, 0.7682869474772277`}, {19, 
    0.7662377379751114`}, {20, 0.7646469190983587`}};

nlm = NonlinearModelFit[data4, 1 E^-(x - a)^2/2 c^2, {{a, 1}, {c, 3}},
   x]
POSTED BY: joe jill
3 Replies
Posted 5 years ago

Really thankful Mr david, u just made my day... one question why the addition offset is required?

POSTED BY: joe jill
Posted 5 years ago

The Gaussian trends toward zero at +/- infinity, but the data is clearly trending toward a non-zero value.

POSTED BY: David Keith
Posted 5 years ago

Hi Joe,

The problem is that your model does not provide a good fit. It needs a few more terms:

p1 = ListPlot[data4]

enter image description here

(* take our guesses from the data plot *)

model = a Exp[-(x - b)^2/c^2] + offset;

nlm = NonlinearModelFit[data4, model,
{{a, 1}, {b, 10}, {c, 1}, {offset, 1}}, x];


Show[p1, Plot[nlm[t], {t, 0, 20}, PlotRange -> All, PlotStyle -> Red]]

enter image description here

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract