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.py
import numpy as np
import math

def bessel_j0(x, num_terms=50):
    """ゼロ次のベッセル関数 J0(x) を計算する"""
    x = np.asarray(x)  # 入力をNumPy配列に変換
    result = np.zeros_like(x)  # 結果を保存する配列
    for k in range(num_terms):
        term = ((-1)**k / (math.factorial(k) * math.factorial(k))) * (x/2)**(2*k)
        result += term
    return result

# 使用例
x_values = np.linspace(0, 10, 100)
j0_values = bessel_j0(x_values)

print(j0_values)

実行結果

console
[ 1.          0.99745087  0.98982296  0.97717458  0.95960236  0.93724044
  0.91025932  0.87886439  0.84329426  0.80381866  0.7607362   0.71437185
  0.66507419  0.61321244  0.55917343  0.50335827  0.44617906  0.38805542
  0.32941099  0.27066995  0.21225348  0.15457632  0.09804337  0.0430464
 -0.01003911 -0.06085698 -0.10907316 -0.15437834 -0.19649035 -0.23515627
 -0.27015437 -0.30129563 -0.32842509 -0.35142283 -0.37020465 -0.38472241
 -0.39496415 -0.40095376 -0.40275042 -0.40044771 -0.39417246 -0.38408323
 -0.37036864 -0.35324535 -0.33295586 -0.30976607 -0.2839627  -0.25585048
 -0.22574926 -0.193991   -0.16091667 -0.12687306 -0.09220966 -0.05727546
 -0.02241582  0.01203057  0.04573474  0.07838022  0.10966581  0.13930813
  0.16704398  0.1926325   0.21585707  0.23652707  0.25447924  0.26957887
  0.28172071  0.29082952  0.29686048  0.29979911  0.29966114  0.29649188
  0.29036549  0.28138388  0.26967541  0.25539334  0.23871408  0.21983519
  0.19897324  0.17636155  0.15224768  0.12689092  0.10055964  0.07352859
  0.04607618  0.01848171 -0.00897731 -0.0360279  -0.06240414 -0.08784975
 -0.11212048 -0.13498631 -0.15623365 -0.17566718 -0.19311159 -0.20841316
 -0.22144096 -0.23208798 -0.24027192 -0.24593576]

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?