当我运行代码时
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Initial conditions
def f_func(eta,y_in):
y_out = np.zeros(3)
y_out[0] = y_in[1]
y_out[1] = y_in[2]
y_out[2] = -y_in[0]*y_in[2]/2
return y_out
eta = np.linspace(0,8,100)
X0 = [0,0,0.33206]
X = odeint(f_func,X0,eta)
我收到错误
'float' object has no attribute '__getitem__'
当我运行以下 MATLAB 程序时,一切正常。 MATLAB 函数 ode45 相当于 Python 的 odeint。
主程序:
clear
global beta
beta = 1;
initial_value = [0,0,1.2322];
eta = linspace(0,4,100)
[x_out, y_out] = ode45(@falkner_skan,eta,initial_value);
plot(x_out,y_out(:,2))
falkner_skan 函数:
function y_out = falkner_skan(x,y_in)
global beta
y_out(1,1) = y_in(2);
y_out(2,1) = y_in(3);
y_out(3,1) = -y_in(1)*y_in(3) - beta*(1-y_in(2)^2);
end
This https://stackoverflow.com/questions/18091109/float-object-has-no-attribute-getitem and this https://stackoverflow.com/questions/20500021/typeerror-float-object-has-no-attribute-getitem-in-while-statement and this https://stackoverflow.com/questions/20500021/typeerror-float-object-has-no-attribute-getitem-in-while-statement线程似乎没有给我任何指导。