Message Boards Message Boards

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

Getting a curve fit for an outside input/output data set

Posted 12 days ago

Hey there, I'm really new here. A friend recommended this as a tool to solve a tricky problem, so I started my free trial of WolframOne, but I'm struggling to get it working. I've programmed in traditional languages and Matlab script, but things are just different enough to be intensely frustrating.

Long story short, I have a decent set of inputs/outputs, and I'm trying to reverse engineer the function that's used to generate them. Where I'm at:

  • I am able to load the datapoints into arrays

  • I am able to combine the arrays into a table

  • When I try to use FindFormula on that table, I get a piecewise linear approximation, which is clearly incorrect

  • I do not know how to get FindFit to work

Any tips or advice would be appreciated.

POSTED BY: Sammy Berger
4 Replies

Sammy,

depending on your data (!) you alternatively can try with InterpolatingPolynomial[], e.g. like so:

inputs = {16, 22, 114, 118, 120, 121, 122, 126, 128, 131, 141, 161, 177, 213, 225, 237};
outputs = {1.6, 2.2, 10.9, 11.3, 11.5, 11.6, 11.7, 12, 12.2, 12.5, 13.4, 15.2, 16.6, 19.7, 20.7, 21.8};
table = Transpose[{inputs, outputs}];

ipolpol = Simplify[Chop[InterpolatingPolynomial[table, x]]]

(*  Out:   -0.03252010729072907`+0.10366058109484573` x - 0.0001088717878462003` x^2 + 4.586421356854481`*^-7 x^3 - 8.63811125839574`*^-10 x^4  *)
POSTED BY: Henrik Schachner
Posted 10 days ago

Hi Sammy,

Yes, In fact a second degree polynomial is a better fit. Mathematica is capable of very sophisticated curve fitting. I attach a notebook that demonstrates this. In my opinion, curve fitting is most useful when we have a model based on theory, and we use the fit to determine the values of meaningful parameters. Mathematica is very good at that.

Edit: I am not familiar with Wolfram One. If you have trouble opening the notebook let me know.

enter image description here

Attachments:
POSTED BY: David Keith
Posted 12 days ago

Hi Sammy, Look up Fit in the help system. Here is a fit to a line, since a plot of the data looks linear.

data = {inputs, outputs} // Transpose;
dataPlot = ListPlot[data]
fit = Fit[data, {1, x}, x]
(* 0.438595 + 0.0911061 x *)

You can also use LinearModelFit to fit this data, which will also return the fit statistics as properties.

POSTED BY: David Keith
Posted 10 days ago

Hey David, thanks for chiming in. However, this data is nonlinear. The first few points fit directly to y = 0.1x, but once x is over 100, we see that we've dropped slightly below that. By the time we're in the 200s, increasing from 213 to 225 gives an increase of only 1.0, rather than 1.2.

The example you gave of (* 0.438595 + 0.0911061 x *) would mean f(16) ~ 1.9, which is significantly off the observed result of 1.6.

However, whether or not this specific dataset does end up being linear, I have some others that definitely aren't. Do you know how I could get best curve fit that checks for potential logarithmic curves, polynomial curves, and/or sigmoids?

POSTED BY: Sammy Berger
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