日本語 English
株式会社ヒューリンクス
TEL:03-5642-8384
営業時間:9:00-17:30

root

関数 root を使用すると1変数の関数の根 (ルート) を有限区間から求めることができます。別の言葉で言い換えると、関数 root は、有限区間に限定された x に関する方程式 f (x) = 0 の解を求めます。この関数では、関数の定義されていない独立変数の特殊な値、すなわち、孤立特異点 (isolated singularity) を求めることもできます。

構文

rv = root(expr, variable, a, b, maxroots, type)

引数 expr には、解を求める方程式を定義します。この式に範囲または関数のリストを指定すると複数の方程式を同時に解くことができます。方程式は、式リストの各関数に =0 の等式を設定して定義します。引数 variable には、指定した各方程式で解く変数に対応する記号を指定します。すべての方程式で同一の変数が使用されます。引数 ab は、根の探索を実行する区間の左右の各端点です。

引数 maxrootstype はオプションです。maxroots は、最初の引数で指定した各関数を計算する根の最大数です。デフォルトの値は 1 に設定されています。引数 type には、2種類の出力のうちのいずれかを指定する数値を指定します。type = 0 に指定すると、根のみが返されます。type = 1 に指定すると、特異点のみが返されます。デフォルトの値は 0 に設定されています。

戻り値 (Return Value)、すなわち rv は、求められたすべての根のリストまたは範囲です。戻り値の数は、最初の引数で定義した各関数の maxroots の数と常に等しくなります。求められる根が maxroots の数より少ない場合、残りの戻り値は欠損値となります。欠損値を挿入する理由は、別の関数の出力と区別するためです。

役立つチップス

引数 maxroots の数を増やすと、規定区間における方程式のすべての解を求められる可能性が高くなります。また、関数 implicit の処理にかかる時間もそれだけ増加します。

ある方程式の解を複数探索する場合、関数 implicit は、maxroots で指定した区間を等間隔の部分区間に区切ります。そして、部分区間のそれぞれから厳密に1つの解を探索します。結果として、その方程式に与えられた区間において maxroots で指定した数以上の解が実際にあったとしても、関数 implicit は、maxroots よりも少ない解を返します。方程式の区間 ab におけるすべての解を求めるには、maxroots に (ba)/delta よりも大きい値を設定するのが理想的です。ここで、delta は、すべての解に最も近い値を見積もります。

関数 implicit の出力は常にソートされ、引数 expr で指定した関数の根ごとに昇順で出力されます。

例 1

  • この例では、値の範囲を使用して少しだけ違う方程式のリストを作成します。各方程式に対して根が2つずつ求められ、ワークシートにその値が返されます。v はユーザー定義関数の仮引数なので、その値は初期化する必要はありません。
    a=1
    b=0
    c=1
    x= data(.1,.9,.1)
    k(v)=a*x^2+b*x*v+c*v^2-1
    col(2)=root(k(v),v,-10,10,2)

例 2

  • 方程式 x^2+3*x-7=0 の根を2つ見つけます。x が上記の例のようなユーザー定義関数の仮引数である場合を除き、トランスフォーム言語で使用する変数はいずれも初期化する必要があるので、x に初期値 1 を設定する点に注意してください。x に設定する最初の値は重要ではありません。
    x=1
    f=x^2+3*x-7
    col(1)=root(f,x,-10,10,2)

例 3

  • この例は、上記内容と同じですが、より直接的に記述したものです。
    x=1
    col(2)=root(x^2+3*x-7,x,-10,10,2)

例 4

  • この例では、範囲表記を使用して、関数 root の最初の引数に複数の関数を入力します。この場合、3つの関数それぞれに対して2つの根を計算し、6つの値をワークシートに返します。
    x=1
    f=x^2+3*x-7
    g= cos((x+1)/5)
    h=x*arctan(x)+.5*ln(x^2+1)-2
    col(1)=root({f,g,h},x,-10,10,2)

    g の根を求める際 x の値をラジアン単位で解釈できるよう、このトランスフォームの角度単位にはラジアンが設定されていると考えられます。出力には、はじめに関数 f の根がリストされ、その後に他の2つの関数の根がリストに表示される順番に従って続きます。

root

Use the root function to find the roots of a function of one variable over a finite interval. In other words, the root function solves equations of the form f(x) = 0, where x is restricted to lie in a finite interval. This function also has the capability of finding certain values of the independent variable where the function is undefined, known as isolated singularities.

Syntax

rv = root(expr, variable, a, b, maxroots, type)

The expr argument defines the equations to solve. The expression can specify a range or list of functions so that more than one equation can be solved at a time. The equations are defined by setting each function in the expression list equal to zero. The variable argument is the symbol for the variable you are solving for in each specified equation. The same variable is used for all equations. The a and b arguments are the left and right endpoints, respectively, of the interval over which the root search takes place.

The maxroots and type arguments are optional. Maxroots is the maximum number of roots to compute for each specified function in the first argument. The default value is 1. Type is a number that specifies one of two types of output. If type = 0, then only roots will be returned. If type = 1, then only singularities will be returned. The default value is 0.

The Return Value, or rv, is the list or range of all of the roots that were found. The number of values returned will always be equal to maxroots for each function specified in the first argument. If fewer roots than maxroots are found, then the remaining values returned will be missing values. The reason for inserting the missing values is so the output of the different functions can be distinguished.

Helpful Tips

  • Increasing the value of maxroots increases the chances of finding all of the solutions of the equation in the prescribed interval. It also increases the time required to complete the processing of the implicit function.
  • When searching for multiple solutions to an equation, the implicit function partitions the interval that you specify into maxroots equally-spaced subintervals. It then searches each subinterval for exactly one solution. As a consequence, the implicit function may return fewer than maxroots solutions, even though the equation actually has maxroots or more solutions in the supplied interval. Ideally, to find all of the solutions to the equation over the interval from a to b, set maxroots to a value greater than (b -a)/delta, where delta estimates the closest distance between any solutions.
  • The output of the implicit function is always sorted to give the roots in ascending order for each function in expr.

Example 1

  • This example uses a range of values to create a list of slightly modified equations. Two roots are found for each of the equations and the values are returned to the worksheet. Since v is a formal argument to a user-defined function, its value need not be initialized.
    a=1
    b=0
    c=1
    x= data(.1,.9,.1)
    k(v)=a*x^2+b*x*v+c*v^2-1
    col(2)=root(k(v),v,-10,10,2)

Example 2

  • Finds the two roots of the equation x^2+3*x-7=0. Note that x is initially set to 1 since each variable that is used in the transform language must be initialized unless it is a formal argument in a user-defined function as in the example above. The value that x is initially set to doesn’t matter.
    x=1
    f=x^2+3*x-7
    col(1)=root(f,x,-10,10,2)

Example 3

  • This third example is the same as above, but more direct.
    x=1
    col(2)=root(x^2+3*x-7,x,-10,10,2)

Example 4

  • This example uses range notation to enter multiple functions in the first argument of the root function. In this case, two roots are computed for each of three functions and the six values are returned to the worksheet.
    x=1
    f=x^2+3*x-7
    g= cos((x+1)/5)
    h=x*arctan(x)+.5*ln(x^2+1)-2
    col(1)=root({f,g,h},x,-10,10,2)

It is assumed that the angular unit for this transform has been set to radians so that the value of x is interpreted in units of radians when finding the roots of g. In the output, the roots of function f are listed first, followed by the roots of the other two functions according to the order in which they appear in the list.