# Accessing nonlinear fit coefficients

I have performed a nonlinear fit onto a set of data according to the form $$a+b\cos(2\pi x)+c\sin(2\pi x)+d\cos(4\pi x)+e\sin(4\pi x)$$. How do I access the best fit parameters $$a,b,c,d,e$$, store them into a list perhaps?

Once you have the model

model = NonlinearModelFit[data, a + b Cos[2π x] + c Sin[2π x] + d Cos[4π x] + e Sin[4π x],
{a, b, c, d, e}, x]


you can extract individual parameters with, for example,

a /. model["BestFitParameters"]
(*    a real number    *)


or all of them at once in the order you like,

{a, b, c, d, e} /. model["BestFitParameters"]
(*    list of five real numbers    *)


I'd like to point out that your fit is actually a linear one, so you can do more efficiently

model = LinearModelFit[data, {1, Cos[2π x], Sin[2π x], Cos[4π x], Sin[4π x]}, x]


and get the list of best-fit parameters in the same order as the list of functions,

model["BestFitParameters"]
(*    list of five real numbers    *)


If you name model=NonlinearModelFit[...]

model["BestFitParameters"]


is what you are looking for I think.

• Thank you, but how would I store the individual values of $a,b,c,d,e$ into lists? – Houndbobsaw Jun 4 '19 at 6:34
• Values[nlm["BestFitParameters"]] creates the list! – Ulrich Neumann Jun 4 '19 at 6:41