poly,polyl
math.h:インデックス への移動
ヘッダーファイル
math.h
カテゴリ
演算ルーチン
プロトタイプ
double poly(double x, int degree, double coeffs[]);
long double polyl(long double x, int degree, long double coeffs[]);
説明
引数から多項式を生成します。
poly は,coeffs[0],coeffs[1],...,coeffs[degree] を係数とする x の degree 次多項式を生成します。たとえば,n = 4 の場合,生成される多項式は,coeffs[4] * (x^4) + coeffs[3] * (x^3) + coeffs[2] * (x^2) + coeffs[1] * x + coeffs[0] になります。
polyl は long double バージョンです。long double 引数を受け取り,long double の結果を返します。
戻り値
poly および polyl は,指定された x に対して評価された多項式の値を返します。
例
#include <stdio.h>
#include <math.h>
/* 多項式:x^3 - 2x^2 + 5x - 1 */
int main(void)
{
double array[] = { -1.0, 5.0, -2.0, 1.0
};
double result;
result = poly(2.0, 3, array);
printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n", result);
return 0;
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
poly |
+ |
|||
polyl |
+ |