Message Boards Message Boards

0
|
11346 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Fitting of a data set with a known equation

Posted 9 years ago

Hi, I have a data set (X, Y) such that Y = f(X, a, b). I want to fit the data point with this equation to determine the values of a and b. I am having following issues - 1. First, I want to know how to insert a table with 2 columns having values (x1, y1), (x2, y2).... with headers "X" and "Y" known to mathematica, as only then I can use a function like FindFit with X and Y defined. 2. If some other method could be easier, please let me know.

Here is a parallel example to explain my problem - There is a (X, Y) data set (2, 5), (4, 9) (5, 16), (7, 28) ..and so on. i know that Y = aX+b. Now I want to fit the data point to determine the values of a and b.

thanks a lot

POSTED BY: S G
4 Replies
Posted 9 years ago

Hi. Just some additional ideas:

data={{2,5},{4,9},{5,16},{7,28}};

LinearModelFit[data,x,x]//Normal

-6.615384615384621+4.692307692307693 x

Full Precision:

PolynomialFit[data[[All,1]],data[[All,-1]],2]

{-(86/13),61/13}

%//N

{-6.615384615384615,4.692307692307693}

Below Code Reference:

http://mathworld.wolfram.com/notebooks/Statistics/LeastSquaresFitting.nb

PolynomialFit[x_List,y_List,n_]:=Module[
{X,i,k},X=Table[Table[x[[i]]^(k-1),{k,n}],{i,Length[x]}];
LinearSolve[Transpose[X].X,Transpose[X].y]
]

HTH Dana

POSTED BY: Dana DeLouis
data = {{2, 5}, {4, 9}, {5, 16}, {7, 28}};

TableForm[data, TableHeadings -> {None, {"x", "y"}} ]

FindFit[data, a*x + b, {a, b}, x]

{a -> 4.69231, b -> -6.61538}
POSTED BY: Frank Kampas
Posted 9 years ago

Hi Frank, Thanks for your help, your suggestion worked fine. Now I am having another issue, in this data fitting I am getting the unexpected values of of parameters a & b and now want to fix the domain of variables. How can I do it in FindFit function.

So, i want to fit (X, Y) data set (2, 5), (4, 9) (5, 16), (7, 28) to the equation Y = aX+b to determine the values of a and b but with condition that they lie in the range a1 < a < a2 and b1 < b < b2.

Thanks once again..

POSTED BY: S G

The FindFit documentation list a call FindFit[ data, {expr, cons}, pars, vars] for putting in parameter constraints.

POSTED BY: Frank Kampas
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