Solving quartic equations, something's not working - Page 1
Forum section: electronics / projects

author: MathWizard
author_rank: Super Contributor
timestamp: September 22, 2023, 05:28:17 am
content: I can follow along and work out the steps for a cubic equation, and I made a calculator spreadsheet, in Open Office, and it works pretty good for something like x^3-9x^2+36x-80=0. The 2 equal sets of roots are 5, (2+/-j2*SQRT(3))In the spread sheet it seems to get it right, and plugging it into the cubic eqn, it's not exactly zero, it's numbers like (-9.9*10e-13 + j1.3*10e-14)So for a quartic equation, of a transfer function, in the s-domain, I just want to factor it. I'm pretty sure the circuit equations for it are spot on, and the LRC terms. I've calculated and graphed it in other ways and it matches great.I can follow along and work out the method on wikipedia, going from a general quartic, to depressed quartic, to resolvent cubic. All constants are just real, LRC combo's, and I'm just treating the 4th and 3rd order poly's as real.But when I get to the step of making the resolvent cubic, 8m^3 +8pm^2 +(2p^2-8r)m-q^2=0 something goes wrong. From there the cubic solver gives roots that don't solve to zero, in the resolvent cubic, but instead to a magnitude of 10^37. So never mind making the 4th order roots, the roots of the resolvent cubic, 8m^3 +8pm^2 +(2p^2-8r)m-q^2=0, aren't working.But if I take x^3-9x^2+36x-80=0, call that a resolvent cubic, and work back a few steps to the depressed quartic withy^4 + py^2 + qy +r =0, well the spreadsheet calculator I made still works fine.So I don't get what could be going wrong if I just start from a_4*s^4 + a_3*s^3 + ..... with my LRC combo's that match great in other equations, the magnitudes and phases.I'm solving cubics like in this pdf below, and I'm following this little part of a wiki page for the quartic's, and I can do it, and it's entered into the spreadsheet right, I rechecked lot's of stuff many times, so what else could be wrong here ?http://mathforcollege.com/nm/mws/gen/03nle/mws_gen_nle_bck_exactcubic.pdfAbout 1/2 way down this wiki page is mainly what I tried for quartics so far.https://en.wikipedia.org/wiki/Quartic_function#Converting_to_a_depressed_quarticQuoteSo my Cardano spreadsheet calculator seems to work fine, but not when coming from the 4th order poly, in s, that I'm leaving as s, not jw.My coefficients are5.821323366E-25 for s^44.860381796E-19 for s^3...etc5.633629942E-102.225651784E-041.000000000E+00All the units match, the each term when multiplied by the omega's, leaves no units. On my graphic calculator, there are no real roots in the graph.

author: IanB
author_rank: Super Contributor
timestamp: September 22, 2023, 06:13:30 am
content: I can't help you, because I've never tried using this method.The reason I've never tried using this method is because it is pretty unusual for anyone to try solving polynomials analytically. I've seen it done for cubics, but even then the justification is dubious. For quartics, that seems like a lot of work.Analytical solutions are of interest academically to mathematicians, but less so for working practitioners.In general, unless equations are simple, engineers tend to favor numerical solution approaches.Or, you could just use something like Wolfram Alpha and get the answer quickly and reliably.

author: MathWizard
author_rank: Super Contributor
timestamp: September 22, 2023, 06:41:14 pm
content: Well I still want to find what's going wrong with this method, but as an approximation, I tried dropping the a_1*s+1 part, and solving the remaining part as a cubic , and that gets the correct oscillation frequency as a root, I'll have to check what that does for the overall magnitude of the circuit gain.I read something about approximating the Q of a circuit, and somehow reducing higher degree transfer functions with that. I heard a prof. say that most circuits, like the internals of an op-amp for instance, can be reduced to 1st or 2nd order equations.What techniques or topics should I be looking up for simplifying higher order equations ? Back when everyone used slide rulers, and computers were rare, what would they do ?Ok 1 is the Dominant Pole Approximation

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 22, 2023, 06:54:54 pm
content: I have some vague memories of Newton-Raphson. There were two ways of setting up the iteration formula and usually only one of them converged, and the iteration formula that was easiest to derive usually was the one that did not work.In school I was also forced to do Runge-Kutta a few times by hand. (second or third order? I can't remember). That was both a weird and wonderful beast.In real life those things are hidden far away in libraries that are programmed by people who are far smarter than I am, and one thing I learned from those exercises in school is that mathematics is not (always) as beautiful and elegant as you'd like it to be.

author: IanB
author_rank: Super Contributor
timestamp: September 22, 2023, 06:56:45 pm
content: Higher order equations may often result from dynamic systems that have several time constants. One way to reduce the order is to keep only the dominant (larger) time constants and to discard any small time constants (ones which might be close to zero).Another way to look at this mathematically is in terms of eigenvalues and eigenvectors and to discard the less significant ones (this might be called principle component analysis, for example).To do this in a non-mathematical way, you could plot the higher order polynomial, find the region of interest (for example, where the main operating point lies), and then refit that local part of the curve to a lower order polynomial (linear or quadratic).This is overall a very complex topic, and not easy to give a short answer.

author: IanB
author_rank: Super Contributor
timestamp: September 22, 2023, 07:03:14 pm
content: Quote from: Doctorandus_P on September 22, 2023, 06:54:54 pmNewton-Raphson, or Newton's method, is a root finding technique that is very good at finding numerical solutions to equations. It can be used for single equations, or sets of simultaneous equations. I use it every day in my work (usually built into software that applies it).QuoteRunge-Kutta is a method for numerical integration of differential equations. It and other similar numerical techniques are also used far more often than analytical methods.QuoteTrue about the libraries.

author: ledtester
author_rank: Super Contributor
timestamp: September 22, 2023, 07:07:47 pm
content: Using live.sympy.org the roots are (please excuse the unreasonable precision):-390590.824301917-4545.36157461576-219895.556683702 +/- 31105203.6696609*ISince the first two coefficients are very small compared to the others you can get very good approximations to the real roots by dropping them and just solving the quadratic:-390519.952572334-4545.36178338086

author: MathWizard
author_rank: Super Contributor
timestamp: September 26, 2023, 06:06:54 pm
content: Yeah the circuit/eqn was for the open loop gain of a Colpitt's oscillator, I got rid of the by-pass caps, and BJT capacitance's, and then the biggest part is a 2nd order eqn. And using the root of that as a guess, Newton's method finds the complex roots of the 4th order eqn, to a few sig fig's, in 2 steps, it's that's close, being the dominant poles.So my HP calculator plot of the 4th order seems wrong, there are 2 real roots like you say. The a_1*s term has just the sum of 2 RC time constants, just using that value of 4493radHz, N.M. gets the 4545.36 in 3 step's. So I should have tried that earlier.

author: The Electrician
author_rank: Frequent Contributor
timestamp: September 29, 2023, 06:21:25 am
content: What model HP calculator are you using?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 29, 2023, 12:42:44 pm
content: I don't think it helps the code/formulas in question unfortunately (or, necessarily adds anything, you probably know this already--), but for the quartic, either all four roots are real, or one pair is complex and conjugated and two are real, or all four are complex pairs. Which are the consequence of the transfer function having a real impulse response. Finding at least one real root narrows things down considerably (and, after all, you have the cubic solution set up to go from there if needed), and that leaves the all-complex form as exceptional.I don't know nearly enough about resolvents to know if these facts are helpful for it, though.For my part, the last quartic I needed to solve, was... I think all-real anyway, and yielded rapidly to numerical methods.Tim

author: MathWizard
author_rank: Super Contributor
timestamp: October 04, 2023, 09:12:32 am
content: It's an HP PrimeYeah in the end I found all 4 root's with Newton's method, and using approximations and a 1st order time constant, as the starting guesses.And 1 way I checked it, was with long division, by 2 roots, and I had a bit of trouble getting it working in the spreadsheet. But finally I did get remainder zero.Now I'm trying to get the total closed loop gain of this LC oscillator with more parasitic's included, and it's a 6th order equation on bottom, with some roots almost the same as the 4th other eqn. Using N.M. I found 2 real ones, and a complex pair. Any real number I've tried leads to either root1 or root2's basin. Otherwise I just seem to get the same complex pair I already have for any complex number I tried.I tried long division, exactly like I always to it, with (s-r1)(s-r2)(s-r3(s-r4) multiplied out on paper with correct negative real roots, etc, but I get huge remainders. IDK if it's the spreadsheet or some mistake I'm doing in that.I worked out the ABCD param's for the common-base amp block and tank/feedback block, and can get the correct magnitude and phase like LTSpice for each, and using them I get the correct open loop gain Av3.But putting those it into the total closed loop gain eqn for positive feed, Gv=Av1/(1-Av3), it doesn't match LTspice, it's the wrong shape. IDK what's going wrong, open loop gain Av3 magnitude matches perfect between ~100Hz and 500MHz, the phase matches over a narrower range but is the same shape still.So that's why I want to get the 6th order roots, and work all that out and see if it matches anything. I guess I'll try a solver for the last 2.

author: The Electrician
author_rank: Frequent Contributor
timestamp: October 04, 2023, 06:03:06 pm
content: What are your 6th order coefficients?The "PROOT" command in your prime should have no trouble finding the roots of a 6th order polynomial. The accuracy degrades if there are identical roots (roots of multiplicity greater than one), or nearly so. This command uses Laguerre's method, and works even if the polynomial's coefficients are complex themselves.

author: The Electrician
author_rank: Frequent Contributor
timestamp: October 04, 2023, 06:54:51 pm
content: I solved your quartic using PROOT on my HP50g. It finds the 4 roots, but the accuracy isn't great due to those two very tiny coefficients.You could try Wolfram Alpha:https://www.wolframalpha.com/examples/mathematics/algebra

author: The Electrician
author_rank: Frequent Contributor
timestamp: October 04, 2023, 07:41:51 pm
content: MathWizard,There's an article titled "Matrix Analysis of Oscillators and Transistor Applications" which was published in the September issue of "IRE Transactions on Circuit Theory". If you don't have easy access to the old IRE publications, PM me a good email address and I'll email it to you.

author: MathWizard
author_rank: Super Contributor
timestamp: October 05, 2023, 05:20:39 am
content: Ok on my HP Prime I got proot(M1) to work where M1 is a vector/matrix I made with the coeff's, I see the guides using square brackets, it there a way to enter them directly to make vectors ? Looking up square brackets I didn't see any answers right away, so I tried the matrix menu.Well great, because Wolfram's solver and another one, wouldn't solve the 6th order for some reason. And I just tried in Octave GNU, enteringc = [, , , ...]roots (c)and it's not showing me any result, it just jumps to a new blank line.There is only 1 complex pair, with an angle of +/-80deg, as Newton's method said, in the 4th order eqn it stays just inside the left halve plane.I've taken to calling rad*Hz =Hr, I hardly ever use hours, so why not.1 missing real root is -202MHr, IDK my NM didn't find it. I found -391kHr, Hp prime has -394kHr and -388KhrIn LTspice, what are the rules for the small signal AC analysis reference AC amplitude ? I've noticed lately that some currents weren't what I expected in Bode plots, because of the AC mag I had set to 1, in a voltage source. To get the expected answer, I had to use some calculated value for AC mag.Also for my BJT oscillator circuit, I put the AC amp=1, in the DC voltage source of the circuit. And then to see the gain, I would look at nodes V(out)/V(in) in the Bode plot. Is that fine ?What about for the AC model of the oscillator circuit, which has no power source, and I'd have to close the loop. I tried putting a 0V source in series to the input and output nodes, and setting AC AMP=1 in it, but IDK if that's really right or not.

author: ejd.pol
author_rank: Contributor
timestamp: October 05, 2023, 08:09:50 am
content: Hi, it seems there is something going on that "degenerates" the equation.In order to use the "generic" equation, some restrictions must be applied.These restrictions are there to make sure that the generic formula makes sense.I think you already gave evidence of this in your first post: the solutions blow up.That blowing up usually means that somewhere in the process, there is a division by a very small number.And as small numerical errors (rounding, floating point precision) can have a big impact on small numbers(and especially on the result of dividing by them), the results go off into fireworks.So, _before_ you can apply the generic solution, you _must_ check for the degenerate cases!That is also the order in which things are done in the wiki page.And be careful: in floating-point land, that should also include almost-degenerate cases.Usually the check for a degenerate case is about something being equal to something else.(And that is usually because in the generic formula at some point there is a division by their difference or such.)So in practice, you need to check if that something is _approximately_ equal to that something else.Hope this helps!Kind regards, Evert-Jan

author: Infraviolet
author_rank: Super Contributor
timestamp: October 05, 2023, 10:09:32 pm
content: If you need this as a mattr of solving the equations to get a feel for a systems behaviour, rather than working to understand the maths behind solving quartics, I'd recommend getting away from spreadsheets and trying a programming language. Try R with R studio or Python with matplotlib, both give you plenty of libraries you can call to solve equations for you, and to plot graphs of how solutions wil vary with changing coefficients, including 3D graphs so you can see the effect of varying two parameters at once.I'm making a guess here, but maybe your spreadsheet software makes rounding errors large enough to throw off your current calculations? All computing will do this ofcourse, but R or Python might hold values to greater precision than spreadsheet software, and would give you mroe chance to look step by step at what is going on and see where in the sequence of calculations things start misbehaving.

author: The Electrician
author_rank: Frequent Contributor
timestamp: October 06, 2023, 05:09:51 am
content: Quote from: MathWizard on October 05, 2023, 05:20:39 amCould you post the 6th order coefficients?Are you interested in the article I mentioned: "Matrix Analysis of Oscillators and Transistor Applications"?

author: MathWizard
author_rank: Super Contributor
timestamp: October 06, 2023, 05:12:06 am
content: Yeah in Octave, copying a cell from the spreadsheet into octave, for some reason makes the >> prompt go away, and I had to restart it, then the root finder was working.The coeff's of the 6th order are11.92810415E+08-9.43474050E+141.94640820E+231.53578428E+293.05794216E+341.36085685E+38I can't find an error in the equations for those (but it's just the spread sheet working them out)For the roots, Octave gets, a bit different than the HP Prime, and Newton's method in the spreadsheet, won't find the -202M, and just finds -390,742-2.0222e+08 + 0i5.0968e+06 + 3.0670e+07i5.0968e+06 - 3.0670e+07i-3.9124e+05 + 0i-3.9077e+05 + 0i-4.5538e+03 + 0iI should get more into Octave anyways. IDK what the output of a CB colpitts should really look like, but I don't like the look of it in LTSpice. Where as the total Gv I calculated looks like a broad volcano that dips at the f_osc, but Av1 and Av3 are perfect matches to LTSpice.Yeah I have a few pdf's on Collpitt's Osc, not that I finished them or anything, but ok I'll PM you, I couldn't find it openly online.

author: IanB
author_rank: Super Contributor
timestamp: October 11, 2023, 03:53:25 am
content: Quote from: MathWizard on October 06, 2023, 05:12:06 amThose are not sensible coefficients. I suspect there is something badly wrong with your calculations.

author: MathWizard
author_rank: Super Contributor
timestamp: October 11, 2023, 10:43:34 pm
content: edit: I'm mis-remembering.Well from ABCD param's of the amp and the feedback network, I plotted each of them, and then found Av3=1/(A1A2+B1C2). And the PC did the math. That open loop Av3 matches LTSpice near perfectly.The plot that looks like a volcano, that's Gv=Av1/(1-Av3). And all the ABCD's seemed perfect.Then when I multiplied out directly all that, and had a 4th order poly over a 6th order, as Gv, that's where the negative gets into it for instance. And maybe since it's an oscillator. Breaking that up with the roots, and taking all the magnitudes and angles in the spread sheet, like the others. But upon plotting that result, it has roughly the same shape as the closed loop collector output voltage(in LTSpice) , referenced to ground, so not divided by Vin. But the magnitude was a fair bit off.So something's wrong, but I really can't find what, I've checked it all a few times, , and wrote it all out at least twice. And all the ABCD's seem perfect, when comparing them to the open and short circuit voltages and currents, when applying a 1V or 1A reference input.

author: IanB
author_rank: Super Contributor
timestamp: October 11, 2023, 11:10:06 pm
content: Well, I can't guess what the problem is as this is not my technical domain. But I do know in any other field, if I got polynomial coefficients with the like of E+23 on the end of them, I would not trust them.

author: MathWizard
author_rank: Super Contributor
timestamp: October 11, 2023, 11:20:03 pm
content: Even just picking 10 frequencies, I can't guess how long it would take to work out each part of what went into these plots, with or without a calculator. Either way the OpenOffice spreadsheet is a good tool, I wish Octave GNU had some interface features like a spreadsheet, maybe it does, IDK.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 12, 2023, 03:16:23 am
content: Well, the equivalent to spreadsheet calculations is the element-wise operation, e.g. dividing an array of values by a constant isarray ./ value, etc. Instead of a column of cells, apply the formula to elements of an array.Tim

author: The Electrician
author_rank: Frequent Contributor
timestamp: October 12, 2023, 06:36:49 am
content: Quote from: MathWizard on October 11, 2023, 11:20:03 pmIt's likely that more help for your problem would be forthcoming if you would post a schematic of the circuit you're trying to solve, and describe your method of solution, so we could follow along.

author: zapta
author_rank: Super Contributor
timestamp: October 18, 2023, 05:55:03 pm
content: If it helps, The Wolfram Alpha app gives step by step solution for the real and complex solutions. This is the real part.