Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 르장드르 다항식 및 x, y, z 복소수 점 배열의 의사 Vandermonde 행렬 생성

<시간/>

x, y, z 샘플 포인트가 있는 르장드르 다항식의 의사 Vandermonde 행렬을 생성하려면 Python Numpy에서 legendre.legvander3d() 메서드를 사용합니다. 도 및 샘플 포인트(x, y, z)의 의사 Vandermonde 행렬을 반환합니다.

매개변수 x, y, z는 모두 같은 모양의 점 좌표 배열입니다. 복잡한 요소가 있는지 여부에 따라 dtype이 float64 또는 complex128로 변환됩니다. 스칼라는 1차원 배열로 변환됩니다. 매개변수 deg는 [x_deg, y_deg, z_deg] 형식의 최대 각도 목록입니다.

단계

먼저 필요한 라이브러리를 가져옵니다 -

import numpy as np
from numpy.polynomial import legendre as L

numpy.array() 메서드를 사용하여 동일한 모양의 점 좌표 배열을 만듭니다. -

x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3. + 3.j])

배열 표시 -

print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

데이터 유형 표시 -

print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

두 어레이의 차원을 확인하십시오 -

print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

두 배열의 모양을 확인하십시오 -

print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

x, y, z 샘플 포인트가 있는 르장드르 다항식의 의사 Vandermonde 행렬을 생성하려면 Python Numpy에서 legendre.legvander3d() 메서드를 사용하십시오 -

x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))

예시

import numpy as np
from numpy.polynomial import legendre as L

# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3. + 3.j])

# Display the arrays
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

# Display the datatype
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

# To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))

출력

Array1...
   [-2.+2.j -1.+2.j]

Array2...
   [0.+2.j 1.+2.j]

Array3...
   [2.+2.j 3.+3.j]

Array1 datatype...
complex128

Array2 datatype...
complex128

Array3 datatype...
complex128

Dimensions of Array1...
1

Dimensions of Array2...
1

Dimensions of Array3...
1

Shape of Array1...
(2,)

Shape of Array2...
(2,)

Shape of Array3...
(2,)

Result...
   [[ 1.00000000e+00 +0.0000000e+00j  2.00000000e+00 +2.0000000e+00j
     -5.00000000e-01 +1.2000000e+01j -4.30000000e+01 +3.7000000e+01j
     -2.79625000e+02 -3.0000000e+01j  0.00000000e+00 +2.0000000e+00j
     -4.00000000e+00 +4.0000000e+00j -2.40000000e+01 -1.0000000e+00j
     -7.40000000e+01 -8.6000000e+01j  6.00000000e+01 -5.5925000e+02j
     -6.50000000e+00 +0.0000000e+00j -1.30000000e+01 -1.3000000e+01j
      3.25000000e+00 -7.8000000e+01j  2.79500000e+02 -2.4050000e+02j
      1.81756250e+03 +1.9500000e+02j  0.00000000e+00 -2.3000000e+01j
      4.60000000e+01 -4.6000000e+01j  2.76000000e+02 +1.1500000e+01j
      8.51000000e+02 +9.8900000e+02j -6.90000000e+02 +6.4313750e+03j
     -2.00000000e+00 +2.0000000e+00j -8.00000000e+00 +0.0000000e+00j
     -2.30000000e+01 -2.5000000e+01j  1.20000000e+01 -1.6000000e+02j
      6.19250000e+02 -4.9925000e+02j -4.00000000e+00 -4.0000000e+00j
      0.00000000e+00 -1.6000000e+01j  5.00000000e+01 -4.6000000e+01j
      3.20000000e+02 +2.4000000e+01j  9.98500000e+02 +1.2385000e+03j
      1.30000000e+01 -1.3000000e+01j  5.20000000e+01 +0.0000000e+00j
      1.49500000e+02 +1.6250000e+02j -7.80000000e+01 +1.0400000e+03j
     -4.02512500e+03 +3.2451250e+03j  4.60000000e+01 +4.6000000e+01j
      0.00000000e+00 +1.8400000e+02j -5.75000000e+02 +5.2900000e+02j
     -3.68000000e+03 -2.7600000e+02j -1.14827500e+04 -1.4242750e+04j
     -5.00000000e-01 -1.2000000e+01j  2.30000000e+01 -2.5000000e+01j
      1.44250000e+02 +0.0000000e+00j  4.65500000e+02 +4.9750000e+02j
     -2.20187500e+02 +3.3705000e+03j  2.40000000e+01 -1.0000000e+00j
      5.00000000e+01 +4.6000000e+01j  0.00000000e+00 +2.8850000e+02j
     -9.95000000e+02 +9.3100000e+02j -6.74100000e+03 -4.4037500e+02j
      3.25000000e+00 +7.8000000e+01j -1.49500000e+02 +1.6250000e+02j
     -9.37625000e+02 +0.0000000e+00j -3.02575000e+03 -3.2337500e+03j
      1.43121875e+03 -2.1908250e+04j -2.76000000e+02 +1.1500000e+01j
     -5.75000000e+02 -5.2900000e+02j  0.00000000e+00 -3.3177500e+03j
      1.14425000e+04 -1.0706500e+04j  7.75215000e+04 +5.0643125e+03j]
    [ 1.00000000e+00 +0.0000000e+00j  3.00000000e+00 +3.0000000e+00j
     -5.00000000e-01 +2.7000000e+01j -1.39500000e+02 +1.3050000e+02j
     -1.41712500e+03 -6.7500000e+01j  1.00000000e+00 +2.0000000e+00j
     -3.00000000e+00 +9.0000000e+00j -5.45000000e+01 +2.6000000e+01j
     -4.00500000e+02 -1.4850000e+02j -1.28212500e+03 -2.9017500e+03j
     -5.00000000e+00 +6.0000000e+00j -3.30000000e+01 +3.0000000e+00j
     -1.59500000e+02 -1.3800000e+02j -8.55000000e+01 -1.4895000e+03j
      7.49062500e+03 -8.1652500e+03j -2.90000000e+01 -8.0000000e+00j
     -6.30000000e+01 -1.1100000e+02j  2.30500000e+02 -7.7900000e+02j
      5.08950000e+03 -2.6685000e+03j  4.05566250e+04 +1.3294500e+04j
     -1.00000000e+00 +2.0000000e+00j -9.00000000e+00 +3.0000000e+00j
     -5.35000000e+01 -2.8000000e+01j -1.21500000e+02 -4.0950000e+02j
      1.55212500e+03 -2.7667500e+03j -5.00000000e+00 +0.0000000e+00j
     -1.50000000e+01 -1.5000000e+01j  2.50000000e+00 -1.3500000e+02j
      6.97500000e+02 -6.5250000e+02j  7.08562500e+03 +3.3750000e+02j
     -7.00000000e+00 -1.6000000e+01j  2.70000000e+01 -6.9000000e+01j
      4.35500000e+02- 1.8100000e+02j  3.06450000e+03 +1.3185000e+03j
      8.83987500e+03 +2.3146500e+04j  4.50000000e+01 -5.0000000e+01j
      2.85000000e+02 -1.5000000e+01j  1.32750000e+03 +1.2400000e+03j
      2.47500000e+02 +1.2847500e+04j -6.71456250e+04 +6.7818750e+04j
     -5.00000000e+00 -6.0000000e+00j  3.00000000e+00 -3.3000000e+01j
      1.64500000e+02 -1.3200000e+02j  1.48050000e+03 +1.8450000e+02j
      6.68062500e+03 +8.8402500e+03j  7.00000000e+00 -1.6000000e+01j
      6.90000000e+01 -2.7000000e+01j  4.28500000e+02 +1.9700000e+02j
      1.11150000e+03 +3.1455000e+03j -1.09998750e+04 +2.2201500e+04j
      6.10000000e+01 +0.0000000e+00j  1.83000000e+02 +1.8300000e+02j
     -3.05000000e+01 +1.6470000e+03j -8.50950000e+03 +7.9605000e+03j
     -8.64446250e+04 -4.1175000e+03j  9.70000000e+01 +2.1400000e+02j
     -3.51000000e+02 +9.3300000e+02j -5.82650000e+03 +2.5120000e+03j
     -4.14585000e+04 -1.7194500e+04j -1.23016125e+05 -3.0981225e+05j]]