0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

参考ページ

準備

オンラインコンパイラを使用します。

ソースコード

sample.c


#include <stdio.h>
#include <math.h>

#define NUM_TERMS 50

double bessel_j0(double x) {
    double result = 0.0;
    for (int k = 0; k < NUM_TERMS; k++) {
        double term = pow(-1, k) / (tgamma(k + 1) * tgamma(k + 1)) * pow(x / 2, 2 * k);
        result += term;
    }
    return result;
}

int main() {
    int n = 100;
    double x_values[100];
    double j0_values[100];

    // x_valuesの初期化
    for (int i = 0; i < n; i++) {
        x_values[i] = 10.0 * i / (n - 1);
    }

    // ベッセル関数の計算
    for (int i = 0; i < n; i++) {
        j0_values[i] = bessel_j0(x_values[i]);
        printf("%f\n", j0_values[i]);
    }

    return 0;
}


実行結果

console


1.000000
0.997451
0.989823
0.977175
0.959602
0.937240
0.910259
0.878864
0.843294
0.803819
0.760736
0.714372
0.665074
0.613212
0.559173
0.503358
0.446179
0.388055
0.329411
0.270670
0.212253
0.154576
0.098043
0.043046
-0.010039
-0.060857
-0.109073
-0.154378
-0.196490
-0.235156
-0.270154
-0.301296
-0.328425
-0.351423
-0.370205
-0.384722
-0.394964
-0.400954
-0.402750
-0.400448
-0.394172
-0.384083
-0.370369
-0.353245
-0.332956
-0.309766
-0.283963
-0.255850
-0.225749
-0.193991
-0.160917
-0.126873
-0.092210
-0.057275
-0.022416
0.012031
0.045735
0.078380
0.109666
0.139308
0.167044
0.192632
0.215857
0.236527
0.254479
0.269579
0.281721
0.290830
0.296860
0.299799
0.299661
0.296492
0.290365
0.281384
0.269675
0.255393
0.238714
0.219835
0.198973
0.176362
0.152248
0.126891
0.100560
0.073529
0.046076
0.018482
-0.008977
-0.036028
-0.062404
-0.087850
-0.112120
-0.134986
-0.156234
-0.175667
-0.193112
-0.208413
-0.221441
-0.232088
-0.240272
-0.245936

[Execution complete with exit code 0]
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?