ニュートン法を用いてある関数f(θ)=u×sin(θ)+cos(θ)-0.3を解きたいです。
このときuは変数でuごとにθを求めたいのですがうまくいきません
仮にuを0.05≦u≦0.15としたときに以下のようにエラーが出ます。
D=u[i]*np.sin(theta0)+np.cos(theta0)-0.3
IndexError: index 2 is out of bounds for axis 0 with size 2
というエラーが出ます。
u[i]がなければうまくいきますが何かいい方法はないでしょうか?
u=np.arange(0.05,0.15,0.05)
i=0
theta0=1
eps=0.0001
while i<=len(u):
while True:
f=u[i]np.sin(theta0)+np.cos(theta0)-0.3
df=u[i]2np.cos(2theta0)-np.sin(theta0)
theta=theta0-D/dD
if abs(theta-theta0)<=eps:
break
theta0=theta
i=i+1
print(u[i],round(theta0,2))