How to Get function from data ?

jemal.manjgaladze

New member
Joined
Jun 9, 2020
Messages
1
Hello .

I am doing some numerical experiment in Physics in university. So I obtained (x,y) pairs from computer calculations and i can draw graph of it using program. but i want to know is there any way or any website so that I input my (x,y) pair and it will give me what function is it?


for example I input (1,2) (2,4) (3,6) (4,8) ... and it gives me f(x)=2x.
 
Hello .

I am doing some numerical experiment in Physics in university. So I obtained (x,y) pairs from computer calculations and i can draw graph of it using program. but i want to know is there any way or any website so that I input my (x,y) pair and it will give me what function is it?


for example I input (1,2) (2,4) (3,6) (4,8) ... and it gives me f(x)=2x.
Use a spreadsheet-software like Excel. In there, you will find a "function" called "trend-line". That will choose the "best-fit line" for those points and the functional description.
 
You will need to have some idea of what kind of curve it should be. Linear? Quadratic? Polynomial? Exponential? Logarithmic? Periodic? If you know that, find a website that does least squares fit. Or maybe cubic splines. It all depends on what you are doing and what you expect to get out of it.
 
Or you can work it out exactly. (Not so easy with this one.. I resorted to W|A.) I fit the points to a quartic. It looks a lot like a line, but if we go to higher degree equations there will be more curve in the plot.

-Dan
fit.jpg
 
I'm thinking those three points were just an example and the OP was wanting something that would work more generally as he gets output from his physics experiments.
 
Given any finite number of data points, there exist an infinite number of functions that give those points. In particular, given n points, there exist a unique polynomial of degree n-1. With your example, (1,2) (2,4) (3,6) and (4,8), if we didn't notice that they all lie on a straight line, we could try to find a, b, c, d, so that \(\displaystyle f(x)= ax^3+ bx^2+ cx+ d\) satisfied that.
We would have
f(1)= a+ b+ c+ d= 2
f(2)= 8a+ 4b+ 2c+ d= 4
f(3)= 27a+ 9b+ 3c+ d= 6
f(4)= 64a+ 16b+ 4c+d= 8,
four equations to solve for a, b, c, and d.

Subtracting the first equation from the second, we eliminate d and have
7a+ 3b+ c= 2.
Subtracting the third equation from the fourth, we also eliminate d and have
37a+ 7b+ c= 2
And subtracting the second equation from the third
19a+ 5b+ c= 2

Subtracting the first of those from the second, 30a+ 4b= 0.
Subtracting the third of those from the second, 18a+ 2b= 0

Subtracting twice the second of those from the first, -6a= 0 so a= 0.
Gosh who'd have guessed that!

Of course then 30a+ 4b= 4b= 0 so b= 0 also.

7a+ 3b+ c= c= 2.

And a+ b+ c+ d= 2+ d= 2 so d= 0.

\(\displaystyle f(x)= 0x^3+ 0x^2+ 2x+ 0= 2x\).

That was a lot of work for an obvious result!
 
Last edited:
Top