前提・実現したいこと
python初心者です。
惑星とその周りを楕円運動する衛星の軌道を、微分方程式を解くことでプロットしようとしています。
発生している問題・エラーメッセージ
動径をr、系の慣性軸と衛星惑星をむすぶ直線がなす角をfとしてひとまず値を得ることが出来ましたが、それが本当に楕円軌道を描いているのか(正しく数値計算出来ているか)を確認するためにデカルト座標にプロットしたいのですが、変換のサンプルコードを用いても座標データの代入が間違っているのか、エラーが出ます。
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-16-c7b0c13ef6ac> in <module> 81 position = (u_list[:,0], u_list[:,1]) 82 ---> 83 polar2cartesian(position) <ipython-input-16-c7b0c13ef6ac> in polar2cartesian(position) 72 def polar2cartesian(position): 73 ---> 74 num = position.shape[0] 75 newposition = np.empty([num,2], dtype=np.float64) 76 newposition[:,0] = position[:,0]*np.cos(position[:,1]) AttributeError: 'tuple' object has no attribute 'shape'
該当のソースコード
import math import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt t_min = 0.0 t_max = 10.0 N = 1001 n = 2*np.pi a = 1.0 e = 0.1 k = n*a*pow(1-e*e, -1/2) def func(u, t, k, n, a, e): r = u[0] f = u[1] x1 = u[2] # γ x2 = u[3] # dγ/dt drdt = k*e*math.sin(f) dfdt = k*math.cos(f)/r dx1dt = x2 dx2dt = -0.02*n*n*pow(a/r, 3)*math.sin(2*x1-2*f) return ([drdt, dfdt, dx1dt, dx2dt]) t = np.linspace(t_min, t_max, N) # 時間刻み u0 = [1.0, 0.0, 0.0, 0.0] # r,f,γ,dγ/dtの初期値 u_list = odeint(func, u0, t, args=(k, n, a, e)) #print(u_list) # 可視化 def plot1(x, y): fig = plt.figure() sol = fig.add_subplot(1,1,1) sol.set_xlabel("γ", fontsize=20, fontname='selif') sol.set_ylabel("dγ/dt", fontsize=20, fontname='selif') sol.tick_params(axis='both', length=10, which='major') sol.tick_params(axis='both', length=5, which='minor') sol.set_xlim([0.0, np.pi]) sol.set_ylim([-1.0, 2.0]) sol.minorticks_on() sol.plot(x, y, 'b-', markersize=5) fig.tight_layout() plt.show() plot1(u_list[:,2], u_list[:,3]) def polar2cartesian(position): num = position.shape[0] newposition = np.empty([num,2], dtype=np.float64) newposition[:,0] = position[:,0]*np.cos(position[:,1]) newposition[:,1] = position[:,0]*np.sin(position[:,1]) return newposition position = (u_list[:,0], u_list[:,1]) polar2cartesian(position)
試したこと
補足情報(FW/ツールのバージョンなど)
Python3をAnacondaで使っています。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/17 06:29
2020/01/17 07:00 編集
2020/01/17 06:49
2020/01/17 06:51
2020/01/17 06:58 編集
2020/01/17 07:46
2020/01/17 07:50
2020/01/17 08:19
2020/01/17 08:28
2020/01/17 08:28
2020/01/17 09:07
2020/01/17 09:09
2020/01/17 09:34 編集
2020/01/17 16:37