関数eqsol3 マニュアル

(The documentation of function eqsol3)

Last Update: 2021/11/30


◆機能・用途(Purpose)

3次方程式 (1)ax3+bx2+cx+d=0(a0) の解を求める。
Calculate the solution of a cubic equation (1).


◆形式(Format)

#include <equation.h>
inline struct im ∗eqsol3
(const double a,const double b,const double c,const double d)


◆引数(Arguments)

a x3の係数。
The coefficient of x3.
b x2の係数。
The coefficient of x2.
c xの係数。
The coefficient of x.
d 方程式の定数項。
The constant term of the equation.


◆戻り値(Return value)

3次方程式(1)の3つの解(複素数)を並べた配列を関数内で作成し、 その先頭アドレスを返す。
The first address of an array created in this function which consists of the three solutions (complex numbers) of eq. (1).


◆使用例(Example)

struct im ∗solution=eqsol3(1.2,3.4,5.6,7.8);


◆計算式とアルゴリズム (Formula and algorithm)

1. a=0の判定と処理 (Judgement and processings for a=0)

a=0のときは2次方程式として解くことも可能であるが、 気づかず意図しない結果を生じるのを防ぐために a=0の場合はエラー終了する仕様にしている。
Although it is possible to solve a quadratic equation in case of a=0, this function treats a=0 as an error to avoid obtaining unexpected results without awaring it.

a=0であるか否かの判定には関数doublecmpを使用し、 amax{|b|,|c|,|d|}の比較によって判定している。
Function doublecmp is used for the judgement of a=0, where a is compared with max{|b|,|c|,|d|}.


2. a0のときの解 (Solution in case of a0)

3次方程式(1)の解x0, x1, x2は 以下のように与えられる。 (2)xm=r13ei(2θ2θ1+2mπ)/3+r23ei(2θ1θ2+2mπ)/3b3a(m=0,1,2) ここでr1, θ1, r2, θ2は 以下の式によって定義される。 (3)A3acb23a2 (4)B2b39abc+27a2d27a3 (5)CB24+A327Reiϕ(R0;π<ϕπ) (6)D1B2+Reiϕ/2r1eiθ1(r10;π<θ1π) (7)D2B2Reiϕ/2r2eiθ2(r20;π<θ2π) The three solutions x0, x1, and x2 for the cubic equation of (1) are given by eq. (2), where r1, θ1, r2, and θ2 are defined by eqs (3)-(7).

解の導出 (Derivation of the solutions)

解(2)の導出過程は以下の通り。
The solution (2) is obtained as follows.

方程式(1)の両辺をaで割って (8)x3+bax2+cax+da=0 この式の左辺は (9)(x+b3a)3+3acb23a2(x+b3a)+2b39abc+27a2d27a3 と変形できるので、定数A, Bを(3)(4)のようにおき、 (10)Xx+b3a と変数変換すれば (11)X3+AX+B=0 を得る。これを解くために更に (12)X=YA3Y と変数変換すると (13)X3=Y3A327Y3A(YA3Y)=Y3A327Y3AX であるので、これらを(11)式に代入して整理すれば (14)Y6+BY3A327=0 が得られる。
Dividing the both sides of eq. (1) by a results in eq. (8), and the left hand side of this equation is arranged as (9). Defining constants A and B as eqs (3)(4) and converting the variable from x to X as (10) yield (11). A further conversion of the variable from X to Y as (12) gives eq. (13). Inserting eq. (11) into (13), one finally obtains (14).

(14)式はY3についての2次方程式になっており、その解は (15)Y3=B±B2+4A3272=B2±B24+A327 と書ける。 (16)CB24+A327 とおき、このC(17)C=Reiϕ(R0;π<ϕπ) と極座標表示すれば(15)は (18)Y3=B2±Reiϕ/2 と書き直せる。Y3に関するこれら2つの解を (19)D1B2+Reiϕ/2 (20)D2B2Reiϕ/2 とおき、これらを (21)D1=r1eiθ1(r10;π<θ1π) (22)D2=r2eiθ2(r20;π<θ2π) と極座標表示すると、Yに関する解として (23)Y=Y1m,Y2m(m=0,1,2) (24)Y1mr13ei(θ1+2mπ)/3 (25)Y2mr23ei(θ2+2mπ)/3 が得られる。これらYに関する解を(12)に代入すると Xについての解として (26)X=X1m,X2m (27)X1mY1mA3Y1m=r13ei(θ1+2mπ)/3A3r13ei(θ1+2mπ)/3 (28)X2mY2mA3Y2m=r23ei(θ2+2mπ)/3A3r23ei(θ2+2mπ)/3 が得られる。
Eq. (14) is a quadratic equation for Y3, the solution of which is given by eq. (15). We now define C as (16) and represent it in a polar coordinate format as (17). Then eq. (15) reduces to (18). Let D1 and D2 be these two solutions, defined by eqs (19) and (20), and represent them in polar coordinate formats as eqs (21) and (22). Then the solution for Y is given by eq. (23), where Y1m and Y2m are given by eqs (24) and (25), respectively. Inserting these solutions for Y into (12) gives the solutions for X represented by eqs (26)-(28).

ところで(19)-(22)より r1r2ei(θ1θ2)=D1D2=(B2+Reiϕ/2)(B2Reiϕ/2)=B24Reiϕ=B24C(29)=A327 が成り立つ。θ1, θ2の定義範囲より (30)2π<θ1θ2<2π である。これらの性質を用いると(27)(28)を より見通しの良い形に変形でき、両者を比較することができる。 以下ではAの符号に応じて場合分けしてこの比較を行う。
From (19)-(22), one obtains eq. (29), and the definition ranges of θ1 and θ2 mean that the range of θ1θ2 is limited as (30). Using these relations, eqs (27) and (28) can be arranged to more comprehensive forms and can be easily compared. These forms depend on the sign of A.

まずA0のとき、 (29)よりei(θ1θ2)=1となり、 (30)の条件と合わせてθ1θ2=0を得る。 またこのとき(29)より r13r23=A3であるので、 これらの関係を用いて(27)(28)式は (31)X1m=r13ei(θ1+2mπ)/3+r23ei(θ2+2mπ)/3 (32)X2m=r23ei(θ2+2mπ)/3+r13ei(θ2+2mπ)/3 と書き直せる。 これよりX1m=X2mであり、 独立な解としてはX1mのみを考えれば良いことが分かる。
In case of A0, (29) gives ei(θ1θ2)=1, from which one obtains θ1θ2=0 taking into account eq. (30). In this case eq. (29) reduces to r13r23=A3. Using these relations, eqs (27) and (28) can be rewritten as (31) and (32), respectively. Therefore X1m=X2m holds, so that only X1m needs to be considered as the independent solutions.

次にA>0のとき、(29)より ei(θ1θ2)=1となり、 (30)の条件と合わせてθ1θ2=±πを得る。 ところでA>0のときは (16)よりC>B24>0であるので (17)においてR>B24, ϕ=0となる。 したがって(19)(20)式から D1=B2+R>0, D2=B2R<0となり、 θ1=0, θ2=π, θ1θ2=πであることが分かる。 またこのとき(29)より r13r23=A3となるので (27)(28)式は X1m=r13ei(θ1+2mπ)/3r23ei(θ2π+2mπ)/3=r13ei(θ1+2mπ)/3+r23eiπei(θ2π+2mπ)/3(33)=r13ei(θ1+2mπ)/3+r23ei[θ2+2(m2)π]/3 X2m=r23ei(θ2+2mπ)/3r13ei(θ1+π+2mπ)/3=r23ei(θ2+2mπ)/3+r13eiπei(θ1+π+2mπ)/3(34)=r23ei(θ2+2mπ)/3+r13ei[θ1+2(m+2)π]/3 と書き直せる。 これよりX10=X21, X11=X22, X12=X20となり、 独立な解としてはX1mのみを考えれば良いことが分かる。 また、その解については(33)を対称性の良い形に変形すると (35)X1m=r13e2πi/3+i[θ1+2(m1)π]/3+r23e2πi/3i[θ2+2(m1)π]/3 となるが、mの定義を変えて (36)X1m=r13e2πi/3+i(θ1+2mπ)/3+r23e2πi/3i(θ2+2mπ)/3 としても3つの解の順番が変わるだけで解自体は変わらない。
We next consider a case where A>0. In this case, eq. (29) gives ei(θ1θ2)=1, from which θ1θ2=±π is obtained based on eq. (30). Indeed, when A>0, eq. (16) indicates C>B24>0, so that R>B24 and ϕ=0 hold in eq. (17). Then eqs (19) and (20) indicate D1=B2+R>0 and D2=B2R<0, respectively, from which θ1=0, θ2=π, and thus θ1θ2=π are obtained. Eq. (29) also indicates r13r23=A3, so that eqs (27) and (28) are rewritten as (33) and (34), respectively. These equations indicate X10=X21, X11=X22, and X12=X20, so that only X1m are needed as the independent solutions. Eq. (33) can further be arranged to more symmetric form of (35), and shifting the definition of m by 1, which does not change the solutions but changes only the order of them, gives a simpler form of eq. (36).

A0の場合にθ1θ2=0であったこと、 A>0の場合にはθ1θ2=πであったことを踏まえると、 (31)(36)はまとめて X1m=r13e2i(θ2θ1)/3+i(θ1+2mπ)/3+r23e2i(θ2θ1)/3i(θ2+2mπ)/3(37)=r13ei(2θ2θ1+2mπ)/3+r23ei(2θ1θ2+2mπ)/3 と書ける。これがXに関する解であり、(10)に代入すれば xに関する解として(2)が得られる。
Since θ1θ2=0 and θ1θ2=π hold in cases of A0 and A>0, respectively, eqs (31) and (36) can be unified as (37). This is the solution for X, and inserting it into (10) results in the solution for x, given by eq. (2).