Home
Forum: "Main";
Current archive: 2002.01.08;

Down

#### Equation of the third degree. Find similar branches

mashinist   (2001-12-16 23:16) [0]

I’m here, it seems like everyone is already sick of it with my math, but still. Does anyone have a piece of code to solve a third-degree equation of the form ax ^ 3 + bx ^ 2 + cx + d = 0, with a, b, c, d: extended;

Help

Builder   (2001-12-17 02:35) [1]

But isn’t it easier than fucking, sitting down and writing yourself?

Take any book on numerical methods - this is in the first section.

mashinist   (2001-12-17 11:58) [2]

Does not work.

Romkin   (2001-12-17 12:19) [3]

http://alglib.chat.ru/equat/index.html#cube
In my opinion, exhaustively
But, in general, equations above the second degree are usually solved not by exact formulas, but by algorithms for finding the roots of polynomials of the nth degree

savva   (2001-12-17 12:31) [4]

this is what the block diagram editor suggested
``` Procedure CubeEquation (a, b, c: real; var nr: byte; x: array [1..3] of real); // for some reason, the 8 parameters are not described for some reason)) you yourself will describe begin p: = - a * a / 3 + b; q: = 2 * a / 3 * a / 3 * a / 3-a * b / 3 + c; QH: = (p / 3) * (p / 3) * (p / 3) + (q / 2) * (q / 2); if QH = 0 then begin nr: = 3; AH: = abs (q / 2); if AH <> 0 then begin AH: = sign (q) * exp (ln (AH) / 3) end; x [1]: = 2 * AH-a / 3; x [2]: = - AH-a / 3; x [3]: = - AH-a / 3 end else begin if QH> 0 then begin AH: = - q / 2 + sqrt (QH); AH: = sign (AH) * exp (ln (abs (AH)) / 3); BH: = - q / 2-sqrt (QH); BH: = sign (BH) * exp (ln (abs (BH)) / 3); x [1]: = AH + BH-a / 3; if AH = BH then begin nr: = 3; x [2]: = - (AH + BH) / 2-a / 3; x [3]: = - (AH + BH) / 2-a / 3 end else begin nr: = 1; x [2]: = - (AH + BH) / 2-a / 3; x [3]: = (AH-BH) / 2 * sqrt (3) end; end else begin nr: = 3; u: = - q / 2 / sqrt (-p * p * p / 27); u: = arccos (u); x [1]: = 2 * sqrt (abs (p / 3)) * cos (u / 3) -a / 3; x [2]: = - 2 * sqrt (abs (p / 3)) * cos (u / 3 + Pi / 3) -a / 3; x [3]: = - 2 * sqrt (abs (p / 3)) * cos (u / 3-Pi / 3) -a / 3 end; end; end;```

I don’t know whether to trust ...

SergVlad   (2001-12-17 13:58) [5]

To mashinist
Still struggling with your regulators?

Юрий Зотов   (2001-12-17 14:59) [6]

> Romkin © (17.12.01 12: 19)

I allow myself an amendment - above the third, and not the second. For cubic equations, however, there are exact formulas - for example, the Cardano formula. It is much simpler, faster and more accurate.

mashinist   (2001-12-17 15:40) [7]

Thank you!

Pages: 1 whole branch

Forum: "Main";
Current archive: 2002.01.08;