Calculating equation for a graph

64 Views Asked by At

Pardon my idiocy, this question has probably been answered somewhere else but I can't find it.

If I had a straight line graph and I wanted to work out the equation I would use y = mx + c

However how would I work it out if the graph looked something like this: enter image description here

I don't know what you'd call this but some sort of line that goes up and down rather than straight. So is there a function for working that out

Thanks,

2

There are 2 best solutions below

3
On BEST ANSWER

If you have data points like shown in said graph and you connect them with lines, you're basically doing linear interpolation. I take it that you're basically looking for a way to describe this graph as a single function $f(x)$. When plotting such a graph, which is a linear interpolation of points, you have to use a piecewise definition.

Let $y = f(x)$ with

$$f(x) = \begin{cases}2x+1 & \text{if } 0 \leq x < 1 \\ -x+4 & \text{if } 1 \leq x \leq 4 \end{cases} $$

The resulting graph is then

firstgraph

You can see that the subfunctions themselves are still linear functions for the form $y_i = mx+t$.

secondgraph

I also think that you want to take a look at linear interpolation of a data set itself (https://en.wikipedia.org/wiki/Linear_interpolation#Interpolation_of_a_data_set).

4
On

There are infinitely many functions that satisfy a list of points $\{x_i,y_i\}$ (your data, for instance), if the function is allowed to have as many parameters as there are points. Determining those parameters is called fitting the function to the data. A standard choice for obtaining such a function is using what is called a Fourier series.

However, if you're able to find a simpler function that also describes the data well, but doesn't have as many parameters, you're probably on to something (e.g., some structure/law underlying your data). In the case of the graph in your link, though, it seems quite chaotic, and then fitting a function with fewer parameters than points becomes next to impossible.