function particle% x here are x(1)=x, x(2)=y, x(3)=upx, x(4)=upyglobal e k tau r pp cp gy
% parameterse=1*10^-5;k=1;r=0.01;tau=0.1;pp=2.7*10^-3;cp=0.5*10^-3;gy=10;
axis=[0,1,0.5,0];
x0=[0;-0.5;0.5;0];
tspan=linspace(0,2);
[t x] = ode45(@f , tspan , x0);plot(t,x(:,1),t,x(:, 2),t,x(:,3),t,x(:,4))legend('x(t)' , 'y(t)' , 'upx(t)' , 'upy(t)')plot(x(:,1),x(:,3))
end
function dxdt = f( t , x)global e k tau r pp cp gyvx=-(k/2*pi)*x(:,2)/(x(:,1)^2+x(:,2)^2+e);vy=(k/2*pi)*x(:,1)/(x(:,1)^2+x(:,2)^2+e);
dvxdt=-1/2*k^2*pi^2*x(:,2)^2/(x(:,1)^2+x(:,2)^2+e)^3*x(:,1)+1/2*k*pi*x(:,1)/(x(:,1)^2+x(:,2)^2+e)*(-1/2*k*pi/(x(:,1)^2+x(:,2)^2+e)+k*pi*x(:,2)^2/(x(:,1)^2+x(:,2)^2+e)^2);
dvydt=-1/2*k*pi*x(:,2)/(x(:,1)^2+x(:,2)^2+e)*(1/2*k*pi/(x(:,1)^2+x(:,2)^2+e)-k*pi*x(:,1)^2/(x(:,1)^2+x(:,2)^2+e)^2)-1/2*k^2*pi^2*x(:,1)^2/(x(:,1)^2+x(:,2)^2+e)^3*x(:,2);
dxdt = [ x(1) (vx(x(1), x(2))-x(3))/tau+r*dvxdt(x(1), x(2)) x(2) (vy(vy-x(4))/tau+r*dvydt+(pp*gy/(pp+cp))-x(4))/tau+r*dvydt(x(1), x(2))-(pp*gy/(pp+cp))
x(3)
x(4) ];
end
??? Attempted to access x(:,2); index out of bounds because size(x)=[4,1].
Error in ==> particle>f at 29vx=-(k/2*pi)*x(:,2)/(x(:,1)^2+x(:,2)^2+e);
Error in ==> odearguments at 109f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> particle at 20[t x] = ode45(@f , tspan , x0);
这错误要怎么改 真是要了老命了
% parameterse=1*10^-5;k=1;r=0.01;tau=0.1;pp=2.7*10^-3;cp=0.5*10^-3;gy=10;
axis=[0,1,0.5,0];
x0=[0;-0.5;0.5;0];
tspan=linspace(0,2);
[t x] = ode45(@f , tspan , x0);plot(t,x(:,1),t,x(:, 2),t,x(:,3),t,x(:,4))legend('x(t)' , 'y(t)' , 'upx(t)' , 'upy(t)')plot(x(:,1),x(:,3))
end
function dxdt = f( t , x)global e k tau r pp cp gyvx=-(k/2*pi)*x(:,2)/(x(:,1)^2+x(:,2)^2+e);vy=(k/2*pi)*x(:,1)/(x(:,1)^2+x(:,2)^2+e);
dvxdt=-1/2*k^2*pi^2*x(:,2)^2/(x(:,1)^2+x(:,2)^2+e)^3*x(:,1)+1/2*k*pi*x(:,1)/(x(:,1)^2+x(:,2)^2+e)*(-1/2*k*pi/(x(:,1)^2+x(:,2)^2+e)+k*pi*x(:,2)^2/(x(:,1)^2+x(:,2)^2+e)^2);
dvydt=-1/2*k*pi*x(:,2)/(x(:,1)^2+x(:,2)^2+e)*(1/2*k*pi/(x(:,1)^2+x(:,2)^2+e)-k*pi*x(:,1)^2/(x(:,1)^2+x(:,2)^2+e)^2)-1/2*k^2*pi^2*x(:,1)^2/(x(:,1)^2+x(:,2)^2+e)^3*x(:,2);
dxdt = [ x(1) (vx(x(1), x(2))-x(3))/tau+r*dvxdt(x(1), x(2)) x(2) (vy(vy-x(4))/tau+r*dvydt+(pp*gy/(pp+cp))-x(4))/tau+r*dvydt(x(1), x(2))-(pp*gy/(pp+cp))
x(3)
x(4) ];
end
??? Attempted to access x(:,2); index out of bounds because size(x)=[4,1].
Error in ==> particle>f at 29vx=-(k/2*pi)*x(:,2)/(x(:,1)^2+x(:,2)^2+e);
Error in ==> odearguments at 109f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> particle at 20[t x] = ode45(@f , tspan , x0);
这错误要怎么改 真是要了老命了

 
                    
