2

I feel like this question must have been asked before, but I'm just not able to find it. Probably because I just don't know the terminology of my issue...

My question is really simple. I have the following lookup table (is that what it's called?):

Voltage (V) | Battery state of charge (%)
< 53.0      | 0
53.0        | 10
54.1        | 20
56.2        | 30
57.7        | 40
59.1        | 50
60.5        | 60
61.7        | 70
62.8        | 80
63.9        | 90
65          | 100 

and I want to create a function that can return an approximation for the "Battery state of charge" for any Voltage value between 65 and 53.
For example 64.45 could return 95%.

Note: I'm not looking for a 100% perfect solution here, as I probably wouldn't understand it anyway.

Forivin
  • 187
  • 2
    This is called regression analysis. – Samir Khan Aug 24 '16 at 20:31
  • With the "method of the least squares", you search the polynomial with given degree, which fits best considering the given points. – Peter Aug 24 '16 at 20:36
  • You could calculate the polynomial containing exactly the given points, but this would lead to a highly oscillating polynomial. Therefore, a polynomial with low degree ,giving a "good" approximation, is a better choice to model the situation. – Peter Aug 24 '16 at 20:38

1 Answers1

1

Linear regression with degree $2$ gives

$$0.184046 \cdot x^2 - 14.36976 \cdot x + 256.386751$$

which is already a reasonable approximation. Only the value $20$ is not well approximated. I ignored the range $x<53$

To calculate the given polynomial, denote the $x$-values as $x_i$ , the $y$-values as $y_i$ and furthermore the following sums :

$$[x]=\sum_{i=1}^n x_i$$

$$[x^2]=\sum_{i=1}^n x_i^2$$

$$[x^3]=\sum_{i=1}^n x_i^3$$

$$[x^4]=\sum_{i=1}^n x_i^4$$

$$[y]=\sum_{i=1}^n y_i$$

$$[xy]=\sum_{i=1}^n x_iy_i$$

$$[x^2y]=\sum_{i=1}^n x_i^2y_i$$

To get $ax^2+bx+c$ , you have to solve the linear equation system

$$c\cdot n+b\cdot [x]+a\cdot [x^2]=[y]$$

$$c\cdot [x]+b\cdot [x^2]+a\cdot [x^3]=[xy]$$

$$c\cdot [x^2]+b\cdot [x^3]+a\cdot [x^4]=[x^2y]$$

Peter
  • 84,454