# 请问一下我这个for循环哪儿有错

``````tspan=[0 1.6];
no_lines=10;
a=1;
y0=range(-a,a,no_lines);
x0=sqrt.(1 .-y0.^2);
x1=ones(1,length(x0))*2*a;hold();
x1=ones(1,length(x0))*2*a;
y1=y0;
line([x0';x1],[y0';y1'],color= :green); hold();
phi=range(0,2*pi,100);
x=a*cos.(phi);
y=a*sin.(phi);
plot(x',y',color= :red,lw=3);
for lp=1:length(x0)
Y0=[x0(lp) y0(lp) -1 0];
options=odeset("RelTol",1e-5,"AbsTol",[1e-6]);
T,Y,=ode45(ham,tspan,Y0,options);
plot(Y[:,1],Y[:,2],color= :blue);hold();
end
ERROR: MethodError: objects of type Vector{Float64} are not callable
Use square brackets [] for indexing an Array.
Stacktrace:
[1] top-level scope
@ .\REPL[82]:2
``````

``````function dy=ham(t,y)
dy=zeros(4,1);
dy(1)=y(3);
dy(2)=y(4);
dy(3)=-y(1);
dy(4)=-y(2);
``````

`Use square brackets [] for indexing an Array.`

x0(lp) y0(lp)

``````julia> for lp=1:length(x0)
Y0=[[x0(lp)] [y0(lp)] -1 0];
options=odeset("RelTol",1e-5,"AbsTol",[1e-6]);
T,Y,=ode45(ham,tspan,Y0,options);
plot(Y[:,1],Y[:,2],color= :blue);hold();
end
ERROR: MethodError: objects of type Vector{Float64} are not callable
Use square brackets [] for indexing an Array.
Stacktrace:
[1] top-level scope
@ .\REPL[82]:2
``````

x0[lp] y0[lp]

``````julia> for lp=1:length(x0)
Y0=[x0[lp] y0[lp] -1 0];
options=odeset("RelTol",1e-5,"AbsTol",[1e-6]);
T,Y,=ode45(ham,tspan,Y0,options);
plot(Y[:,1],Y[:,2],color= :blue);hold();
end
ERROR: MethodError: no method matching odeset(::String, ::Float64, ::String, ::Vector{Float64})
Stacktrace:
[1] top-level scope
@ .\REPL[83]:3
``````