I keep getting a value error when I try to add the last step to my array x[i+1]=... What am I doing wrong here? allocated arrays with similar code and had no issues earlier. Ay help is appreciated.
Source Code:
import numpy as np
import matplotlib.pyplot as plt
#parameters
sigma=10.
rho=28.
beta=8/3.
ti=0.
tf=100
dt=0.01
#pre-allocation
x = np.zeros(tf)
y = np.zeros(tf)
z = np.zeros(tf)
#initial conditions
x[0]=1.
y[0]=1.
z[0]=1.
#functions
fx= lambda x: sigma*(y-x) #y too?
fy= lambda y: x*(rho-z)-y
fz= lambda z: x*y-(beta*z)
#euler-richardson
for i in np.arange(0,tf-1):
k1_x = fx(x[i])
k1_y = fy(y[i])
k1_z = fz(z[i])
k2_x = fx((x[i]+(0.5*k1_x))*dt) #maybe just dt?
k2_y = fy((y[i]+(0.5*k1_y))*dt)
k2_z = fz((z[i]+(0.5*k1_z))*dt)
x[i+1] = x[i] + k2_x
y[i+1] = y[i] + k2_y
z[i+1] = z[i] + k2_z
Error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
Input In [10], in <cell line: 2>()
8 k2_y = fy((y[i]+(0.5*k1_y))*dt)
9 k2_z = fz((z[i]+(0.5*k1_z))*dt)
---> 11 x[i+1] = x[i] + k2_x
12 y[i+1] = y[i] + k2_y
13 z[i+1] = z[i] + k2_z
ValueError: setting an array element with a sequence.