# How to find the equation of a graph with given coordinates? [duplicate]

Possible Duplicate:
Writing a function $f$ when $x$ and $f(x)$ are known

If I am given 9 co-ordinates of a random graph say for e.g

1. (2,1)
2. (4,3)
3. (7,9)
4. (9,5)
5. (10,3)
6. (11,1)
7. (13,4)
8. (15,7)
9. (17,10)


((this is the plotted graph exactly however it needs to be curved ))

How can i create an equation to approximately fit the graphs trendline curve.

-

## marked as duplicate by robjohn♦, J. M., Gerry Myerson, t.b., Asaf KaragilaJun 2 '12 at 21:55

You should probably say which kind of "equation" or function you want. A priori there are various possibilities to write down a function such that all these points lie on the graph. – Simon Markett May 8 '12 at 18:13
sorry a polynomial equation – Yusaf May 8 '12 at 18:15
You can use an interpolating polynomial, then... – J. M. May 8 '12 at 18:21

One common method is least squares, that is, in this case, find $a_0,a_1$ to minimize $\sum_{i=1}^9 (a_0+a_1 x_i - y_i)^2$, where $(x_i, y_i)$ are your data above. If we let $$D=\begin{bmatrix} 1 & x_1 \\ 1 & x_2 \\ \vdots & \vdots\end{bmatrix}, b= \begin{bmatrix} y_1 \\ y_2 \\ \vdots\end{bmatrix}, a = \begin{bmatrix} a_0 \\ a_1\end{bmatrix},$$ then we can write the problem as $\min_{a \in \mathbb{R}^2} || D a -b ||_2^2.$ The minimizing solution satisfies $$D^T(Da-b) = 0,$$ so we have $a = (D^T D)^{-1}D^T y$. In your case, this (or rather Octave) gives $a=\binom{1.26406}{0.35936}$. So the line $x \mapsto 1.26406+0.35936 x$ is the best-fit line in a least squares sense.
You want to find a polynomial such that a given number of points lie on the graph. observe that every given point is a "condition" on your function. A polynmial of degree $n$ is of the form $$P(x)=a_nx^n+\cdots+a_0$$ and has therefore $n+1$ degrees of freedom. So for $n$ given points a polynomial of degree $n-1$ should do the job. Hence assume $P(x)$ is a solution. Just plug in your given points, one at a time. E.g. $$P(2)=1$$ $$P(4)=3$$ $$\cdots$$ $$P(17)=10$$
You will obtain $n$ linear equations for your $n$ variables which you now have to solve. As an advanced exercise: what does it mean if the system has multiple solutions?