Given A your collection of {x,y} data, just :
FindFit[A, a x + b, {a, b}, x]
(careful, y = ax + bx + c should just be y = (a + b)x + c = dx + c !)
Luca P.
>Hello everybody, I have a list of {x,y} data and from a theoretical
>calculation I know that the data should be fitted by an equation,
>for example:
>y=ax+bx+c; where a, b, c are constant parameters.
>The question is how i can find the best fit for my data finding the
>value of this parameters.
>Do mathematica has a specific function for that?
Yes, FindFit. Assume data is a list of {x,y} pairs. Then
FindFit[data, a x + b, {a,b}, x]
will find values for a and b that represent the best fit (least
squares) line. FindFit supports non-linear models as well
Bob Hanlon
---- dinode...@gmail.com wrote:
=============
Hello everybody,
I have a list of {x,y} data and from a theoretical calculation I know
that the data should be fitted by an equation, for example:
y=ax+bx+c; where a, b, c are constant parameters.
The question is how i can find the best fit for my data finding the
value of this parameters.
Do mathematica has a specific function for that?
Thanks a lot.
Dino
--
Bob Hanlon
>Hello and thanks for your collaboration, I read a little bit and I
>wrote the following code: "when I try to do the FindFit command, the
>parameters have to be positive, so i was searching for the optimal
>values of the parameter that fit the data. How I can modify my code
>in order to find the best parameters fitting the data?I tried to do
>the Norm between the value of the data and the value of the equation
>but i cant do more. Thanks.
>Remove["Global`*"] data = {{1, 1}, {28, 0.719188377}, {54,
>0.35746493}, {81, 0.182114228}, {117,
>0.166082164}, {260, 0.132765531}};
>express = (1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q) "this is the
>equation with which i want to fit the data"
When you want to place constraints on the parameters, using
NMinimize is probably going to work for you better than FindFit.
First create a function that computes the summed square error
In[18]:= ss[x_, y_, k_, p_, q_] :=
Total[((1 - k*x)*(1 - k*x/q)*(1 - p*k*x/q) - y)^2]
Here I've separated the x,y components to simplify the code
In[19]:= {xx, yy} = Transpose[data];
Now, NMinimize can be used to find the desired parameters
In[20]:= NMinimize[{ss[xx, yy, k, p, q], k > 0 && p > 0 && q >
0}, {k,
p, q}]
Out[20]= {0.0178264,{k->0.00204306,p->1.,q->0.348625}}
In[21]:= Show[
ListPlot[data, PlotRange -> All, Frame -> True, Axes -> None,
PlotMarkers -> Automatic], Plot[express /. Last[%20], {x, 0, 300}]]
Shows the estimates give a reasonable fit to the data.