0

I have a non-static set of points

How do I get the equation of a graph passing through all these points? The graph should consist of straight lines, as in the picture

As in the picture below, except that it's not a table, but one equation Example

  • 1
    Have you considered defining a piecewise function, with each part of the function defining a straight line? – insipidintegrator May 31 '22 at 19:39
  • The function should be continuous on the function scope and preferably consist of straight lines – MrBlackLord May 31 '22 at 19:43
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 31 '22 at 19:53
  • Once more, the community Bot doesn't understand the issue ! This question is well formulated with an effort to produce a graphical representation, therefore shouldn't be closed. – Jean Marie May 31 '22 at 20:29

2 Answers2

2

You can define piecewise linear function. If you have nodes $$x_1<x_2<\ldots<x_n$$ and the desired function has to satisfy the set of conditions $f(x_i)=y_i$ for $1\leq i\leq n$ then one can define $f$ by the formula $$f(x) = \frac{y_{k+1}-y_k}{x_{k+1}-x_k}\cdot(x-x_k)+y_k,\quad x_k\leq x\leq x_{k+1}.$$ This defines $f$ on $[x_1,x_k]$.

You can also be interested in splines, which are piecewise polynomial functions and can be not only continuous but also differentiable.

Here is a solution with degree-$1$ splines for the following data :

$$\begin{array}{|c|c|c|c|c|c|} \hline x_i&0&1&3&5&6&9\\ \hline y_i&0&4&1.5&3&-0.5&0\\ \hline\end{array}$$

with solution given by a linear combination

$$f(x)=\sum y_i t_{x_{i},x_{i+1},x_{i+2}}(x)$$

of the piecewise linear continuous "tent functions" (or "triangular functions") defined in the following way:

$$t_{a,b,c}(x)=\begin{cases}&1 \ \ \text{for} \ x=b\\ &0 \ \ \text{for x outside} \ (a,c) \end{cases}$$

Remark: please note that the coefficients of the linear combination of these tent functions are precisely values $y_i$. If we take all coefficients equal to $1$, we will get a trapezoidal function with a plateau sum of these "tent functions" is a "trapezoidal function" with a "plateau at "1".

enter image description here

Fig. 1: All the basis "tent functions" colored in blue, green, purple, black resp. have their maximum equal to $1$.

Jean Marie
  • 81,803
Mateo
  • 4,956
  • Splines with order 1 are piecewise linear (as explicitly desired by the OP). – Jean Marie May 31 '22 at 20:31
  • 1
    That's why I've written that splines CAN also be differentiable (not: ARE). – Mateo Jun 01 '22 at 01:41
  • I agree. As the question is now closed, may I ask you the permission to include in your answer a graphical representation I have made of a solution under the form of a degree-1 spline obtained by a linear combination of a basis of triangular functions adapted to given data ? You would be free to erase it if you do not agree. – Jean Marie Jun 01 '22 at 06:49
  • Sure, do what you consider valuable. – Mateo Jun 01 '22 at 10:12
  • Thanks for your "hospitality". Once more, please, feel free to modify or suppress whatever you don't find appropriate. – Jean Marie Jun 01 '22 at 13:37
1

We can use the Newton interpolation polynomial to get

$$f(x) = \sum_{i = 0}^n a_in_i(x) \; \text{where} \; n_i(x)=\prod_{j = 0}^{i−1}(x−x_j)$$

We can now calculate the divided differences as follows

$$a_0 = y_0 = -6.13$$

$$a_1 = \frac{y_1 - y_0}{x_1 - x_0} = \frac{-3.61 + 6.13}{-0.32 + 9.17} = \frac{84}{295}$$

$$a_2 = \frac{\frac{y_2 - y_1}{x_2 - x_1} - a_1}{x_2 - x_0} = \frac{\frac{-5.6 + 3.61}{4 + 0.32} - \frac{84}{295}}{4 + 9.17} = \frac{-474965}{8391924}$$

$$...$$

The resulting polynomial is

$$f(x) \approx 4.90547\times10^{-6}x^{6}-0.000246778x^{5}+0.00296915x^{4}+0.0154116x^{3}-0.323696x^{2}+0.380018x-3.45477$$

enter image description here