Message Boards Message Boards


Applying "fit" function on set of imported data?

Posted 2 years ago
2 Replies
1 Total Likes


I've manually entered in a few sets of coordinates, in the following way: fit {{2,2, 8}, {4,4,16},{5,5,10},{-1,8,40},{0.7,4,-100}} However, I have many more (about 60K) sets of coordinates, which I would like to run the "fit" function on. I've tried uploading the data as a CSV, excel file etc., but I can't understand how to apply the actual "fit" function to the uploaded set of data.

Any help would be greatly appreciated,



2 Replies

Hi Jonathan,

I guess that to really help you, I would need your data file - or something quite similar to it. I can only show you how this works in principle. So these are the data points you give:

data = {{2, 2, 8}, {4, 4, 16}, {5, 5, 10}, {-1, 8, 40}, {0.7, 4, -100}};

The next thing we need is a reasonable model. This step is a bit of "art". You can plot the data with

ListPointPlot3D[data, PlotStyle -> Directive[Red, PointSize[0.02]]]

to get an idea of what you might want. I thought that it might come from something like this:

model = a x + b y + c Abs[x] + d Abs[y] + e Abs[x + y]

You can then find parameters

params = FindFit[data, model, {a, b, c, d, e}, {x, y}]

and plot everything

Show[Plot3D[model /. params, {x, -2, 6}, {y, 2, 9}], ListPointPlot3D[data, PlotStyle -> Directive[Red, PointSize[0.02]]]]

enter image description here

It also becomes quite clear that this is not really easy to fit: 4 points are nearly in a plane. There is only one which is out of the plane and there are many ways of getting a good fit. I also use too many parameters for this fit. There are 5 points and 5 parameters, which is obviously not really ideal.



Posted 2 years ago

Hi Marco,

Thanks for your reply. I've attached a file with my sample data. What I'm trying to recreate is the functions automatically generated when pasting the following input: fit {{-1.9992,3.9837,390}, {-1.9991,0.8988,-100},{-1.9991,0.8988,-100},{-1.9991,0.8988,-100},{-1.9991,0.8988,86.9565}} The results, automatically generated, were the following:

Least-squares best fits: 45.6196 x+143.689 y-91.2102 (linear)

-61.1776 sin(x)-134.033 cos(x)-137.888 sin(y)-180.428 cos(y)+55.6543 (periodic)

-9.29526 x^2+18.5842 x+19.8163 y^2+46.9359 y-37.156 (quadratic)



Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract