How to invert these equations

182 Views Asked by At

Apologies in advance as maths has never been my strong point (I'm not even sure which tag to use).

I'm developing some software that uses some equations to convert values being read from a hardware device. There are three variations, each with a different number of coefficients:-

$$ y = a + b * x\\ y = a + b * x + c * x^2\\ y = a + b * x + c * x^2 + d * x^3$$

(where x is the value I want to convert, and $a$, $b$, $c$, $d$ are known coefficients).

I now need to create "inverted" versions of each these equations, i.e. I want to calculate $x$ from a known $y$ (so I can convert a user-supplied value and send it back to the hardware). I think I'm okay with the first one:-

$$x = \frac{y - a}{b}$$

But I've no idea how to solve the others. Any help would be much appreciated.

3

There are 3 best solutions below

0
On BEST ANSWER

This is actually technically impossible, in that for any given $y$ there may be several values of $x$ that would generate it. This may not be a problem if you have extra information about $y$ that would allow you to pick out one of those values.

In the second case, you have the equation:

$$y=a+bx+cx^2$$

If you can do the first one, then I assume you're good enough at algebra to put this into the following standard form:

$$-cx^2-bc+(y-a)=0$$

From there you can apply the quadratic formula to get up to two possible values of $y$. You'll have to figure out a way to determine which is the right one.

The last one is much more difficult. There is a formula for solving cubics using square and cube roots, but the calculations might take you through the complex numbers, so you might need specialized software libraries. Also, there are issues with choosing which cube roots to take that might cause problems (basically, if you're not careful, you may get false values).

So I would recommend an iterative method for the last one, such as Newton's method. This allows you to find zeroes of functions. In your case, the symbols used on the Wikipedia article correspond to the following:

$$f(x)=dx^3+cx^2+bx+a-y$$

I'll also give you its derivative so that you don't have to go off and learn calculus:

$$f'(x)=3dx^2+2cx+b$$

I believe there are problems of convergence related to Newton's method (it might not work in all cases), but I can't help you there, I've never studied it in depth.

0
On

The second and third equation are much more complicated, with two distinct problems:

  1. Polynomials of order $n$ have, in general, $n$ roots. This means that for a general polynomial $p(x) = ax^2 + bx + c$, there exist $2$ values of $x$ which satisfy the equation $p(x) = 0$.
  2. The roots of the polynomial do not have to be real numbers but can be complex. For example, for the polynomial $p(x) = x^2+1$, there does not exist any value $x\in\mathbb R$ for which $p(x) = 0$.
0
On

$y = a + (b \cdot x)$

A linear equation: $x = \dfrac{y-a}{b}$

One solution exists (also known as the 'linear root of the equation').

$y = a + (b \cdot x) + (c \cdot x^2)$

A quadratic equation: $x= \dfrac{-b\pm\sqrt{b^2-4(a-y)c}}{2a}$

Two solutions (or 'quadratic roots') exist.

$y = a + (b \cdot x) + (c \cdot x^2) + (d \cdot x^3)$

A cubic equation: no easy general solution exists

Three solutions (or 'cubic roots') exist, though these may not necessarily be real.