I've been trying to get this working, but every time I run the script I get an error saying "Array indices must be positive integers or logical values and points to the dxdt(2) for the error. This is the code:
t = (0:0.1:5);condIni = [0;0;0;0;0];[T,Y] = ode45(@Grua,t,condIni);x1 = Y(:,1);x2 = Y(:,2);x3 = Y(:,3);x4 = Y(:,4);plot(t,x1,'-b','linewidth',2)xlabel('tiempo (s)');ylabel('desplazamiento (m)');figure()plot(t,x2,'-b','linewidth',2)xlabel('tiempo (s)');ylabel('Velocidad (m/s)');figure()plot(t,x3,'-b','linewidth',2)xlabel('tiempo (s)');ylabel('desplazamiento angular (rad)');figure()plot(t,x4,'-b','linewidth',2)xlabel('tiempo (s)');ylabel('Velocidad angular (rad/s)');function dxdt = Grua(t,x)L=3;m=100;M=30;r1=0.05;r2=0.1;R=0.15;ct=0.01;cp=0.1;c=1;K=10;Kb=9;Lb=1e-2;Rb=6.2;J=1e-3;E=100;N=r1/r2;g=9.81;dxdt(1) = x(2);dxdt(2) = (K*L*x(5)-L*ct*x(2)+N*R*cp*x(4)-L*N^2*R^2*c*x(2)+L*R*N*m*g*x(3))/(L(M*N^2*R^2+J));dxdt(3) = x(4);dxdt(4) = ((-cp*x(4)-m*g*L*x(3))/L^2) -((m*R*L*N)/L^2)*((K*L*x(5)-L*ct*x(2)+N*R*cp*x(4)-L*N^2*R^2*c*x(2)+L*N*R*g*m*x(3))/(L(M*N^2*R^2+J)));dxdt(5) = (E-Kb*x(2)-x(5)*Rb)/Lb;dxdt = dxdt';end
Best Answer