Keyword: ランベルトのW関数
概要
本サンプルはランベルトのW関数を求めるC言語によるサンプルプログラムです。 本サンプルは以下に示される入力データxについて関数W(x)の値を求め、出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_lambertW() のExampleコードです。本サンプル及び関数の詳細情報は nag_lambertW のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_lambertW のマニュアルページを参照)1 2 3 4 5 6 7 8
このデータをダウンロード |
nag_lambertW (c05bac) Example Program Data 0 : branch Nag_FALSE : offset 0.5 1.0 4.5 6.0 70000000.0
- 1行目はタイトル行で読み飛ばされます。
- 2行目に実数の分岐を示す値(branch)を指定しています。
- 3行目にxが−exp(−1)からのオフセットとして指定されているかどうかをを示すパラメータ(offset)を指定しています。この場合はxはオフセットではなくランベルトのW関数W(x)の引数であることを意味しています。
- 4~8行目にW関数W(x)のxの値を指定しています。
出力結果
(本関数の詳細はnag_lambertW のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12
この出力例をダウンロード |
nag_lambertW (c05bac) Example Program Results branch = 0 offset = Nag_FALSE x w(x) 5.00000e-01 3.51734e-01 1.00000e+00 5.67143e-01 4.50000e+00 1.26724e+00 6.00000e+00 1.43240e+00 7.00000e+07 1.53339e+01
- 3行目には読み込まれた分岐を示す値が出力されています。
- 4行目には読み込まれた、 xがオフセットかどうかを示すパラメータが出力されています。
- 8~12行目にランベルトのW関数の引数xとW(x)の値が出力されています。
ソースコード
(本関数の詳細はnag_lambertW のマニュアルページを参照)
※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
このソースコードをダウンロード |
/* nag_lambertW (c05bac) Example Program. * * CLL6I261D/CLL6I261DL Version. * * Copyright 2017 Numerical Algorithms Group. * * Mark 26.1, 2017. */ #include <stdio.h> #include <math.h> #include <nag.h> #include <nag_stdlib.h> #include <nagc05.h> int main(void) { /* Scalars */ double w, x; Integer branch; Integer exit_status = 0; char offset[10]; Nag_Boolean offsetenum; NagError fail; INIT_FAIL(fail); printf("nag_lambertW (c05bac) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n] "); scanf("%ld%*[^\n] ", &branch); scanf("%9s%*[^\n] ", offset); /* * nag_enum_name_to_value (x04nac). * Converts nAG enum member name to value */ offsetenum = (Nag_Boolean) nag_enum_name_to_value(offset); printf("\n"); printf("branch = %ld\n", branch); printf("offset = %s\n", offset); printf("\n x w(x)\n\n"); while (scanf("%lf%*[^\n] ", &x) != EOF) { /* * nag_lambertW (c05bac) * Real values of Lambert's W function, W(x) */ w = nag_lambertW(x, branch, offsetenum, &fail); if (fail.code == NE_NOERROR) { printf("%14.5e%14.5e\n", x, w); } else { printf("Error from nag_lambertW (c05bac).\n%s\n", fail.message); exit_status = 1; goto END; } } END: return exit_status; }