How much have you dealt with recursion and/or trees? Just wondering which answer to help you find based on the level of your coursework.

Also, what are your inputs? Is X constant? Are all variables input by the user? Or are you trying to solve for X here. "Solve the equation" can be very ambiguous in this case...

Edited 6 Years Ago by Duki: n/a

I am trying to determine X. As it is a forth order equation there can be 4 values for X. The rest of the numbers are constants.

First off I assume that this is a course work/self-learning problem, otherwise, just use a pre-existing library routine. [GSL/ACM/G4 and others]

The usual place to look for maths stuff is the wolfram site and you get: http://mathworld.wolfram.com/QuarticEquation.html

Ok, that takes you through the solution of both the real and complex cases (constants a to e can be real/complex). [The real case is just a quick optimization of the complex case].

HOWEVER:

If you have coded up quadratic and cubic equations before and understand how the solvers work then you will have no problems. If you haven't done them before, ensure:
(i) You understand how they work [remember that your solver will have to do that in the case that constant a is zero.]
(ii) you have written and tested each of them
(iiI) You understand the special cases of the simpler equations

Your quadratic solver will use the lower level solvers for many of the special cases, e.g.
for the case that the depressed function has a zero x term. You cannot bluntly ignore the zero coefficient terms and just pretend that you want to solve it with the general form. It will give you divide by zero errors, or horrific numerical errors if you try to set zero to a very small number.

The quartic equation has a lot of alternate cases, it becomes an ugly mess of "if statements", in C++, no matter how it is coded up, so it is a trick exercise, you are really going to need a number of test cases to ensure that your code works for most quartic equations. [Remember you can
generate test cases by expanding (x-a)(x-b)(x-c)(x-d)=0 and if a and b are complex and a*==b, the
you can test real coefficients with complex roots]

Numerical accuracy

The quadratic equation (ax^2 + bx+c=0) is coded up by most beginners, in such a way that they get horrible rounding errors in the root finding, the quartic equations is similar in that rounding errors are easy to build into the code. It will easily pay you to put a Newton-Raphson step at the end after your find your root, to further resolve them. This will do two things: it will give you an error term on each of your roots and it will suppress much of the rounding error that builds up in the solution.

Edited 6 Years Ago by StuXYZ: n/a

This article has been dead for over six months. Start a new discussion instead.