What is an algorithm for solving quadratic with linear equation simultaneously?

StackOverflow https://stackoverflow.com/questions/13904638

  •  09-12-2021
  •  | 
  •  

Question

Need an algorithm to solve equation like these:

8*p^2+8*q^2+8*p-16=0
p^2+q^2+12*p+20=0

If anyone can point me to the name of algorithm also it'll be enough. I could have followed any matrix related algorithm but the quadratic inside these linear are causing a problem.

Était-ce utile?

La solution

The Nelder-Mead Algorithm is a very easy-to-program non-linear solver that converges quickly and accurately in low dimensional problems like this one. The pseudo-code is easy to follow on Wikipedia, but you can find some coded implementations online as well.

Your cost function in this case would be the sum of the left hand sides' squares to ensure that lower costs are closer to the correct solutions.

Autres conseils

In the case you wrote about, I'd suggest first subtracting 8 times the second equation from the first.

0 = (8*p^2+8*q^2+8*p-16) - 8*(p^2+q^2+12*p+20) = -88*p-176 = 0
p = -2

Then you are left with a simple quadratic equation in q, which you can solve using the common methods for solving quadratic equations in a single variable.

It's a non-linear problem. You'll need an iterative solution, something like Newton Raphson or BFGS.

Here's a simple approach.

Start by linearizing it:

16*p*dp + 16*q*dq + 8 = 0
2*p*dp + 2*q*dq + 12 = 0

This becomes a linear algebra problem:

| 16*p 16*q |[ dp ]    [  -8 ]
|  2*p  2*q |[ dq ] =  [ -12 ]

You'll start with an initial guess for (p, q):

(p, q) = (p0, q0)

You'll solve for dp and dq, using the usual linear algebra techniques.

You'll update your guesses for p and q:

(p1, q1) = (p0 + dp, q0 + dq)

You'll iterate again until your solution either diverges or converges.

There's no guarantee that it'll converge, depending on your initial guess.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top