How to solve motion equation system using ODE45 solver (six motion equation system, six variables)

3 visualizaciones (últimos 30 días)
Hello, I'm trying to solve my task for get more experience in Matlab. I watched some tutorials on internet and find some examples how to solve the equation system. The example source: http://www.mit.edu/people/abbe/matlab/ode.html
I tried to create equation (function) in matlab *.m file, and when i tried to solve it using ODE45 solver, i got a lot of errors. I'm new on Matlab, so i need some tips and advice about my task:
My *.m File:
function dyt = mokomasis2(t, y)
%---START of Variables:---------------------------------------------------
afi_1 = y(1);
w1 = y(2);
afi_2 = y(3);
w2 = y(4);
q = y(5);
diff(q,t) = y(6);
%---END of Variables:---------------------------------------------------
%---START of Values:------------------------------------------------------
%Line potential energy:
%Ep = ((1/2)*k*(r1*afi_1-r2*afi_2)^2) +((1/2)*k*(r2*afi_2-q)^2);
%System Values:
k=(5.72*(200*10^9))/1; %line density
r1=1.3; %radius 1
r2=0.65; %radius 2
m=500; %body mass
g=9.81; %free fall acceleration
Mv=100; %motor torque N
Mpas1 = k*r1*( r1*afi_1-r2*afi_2); % Mpas1 = -diff(Ep,afi_1);
I1=(Mv-Mpas1)/diff(w1,t); % Moment of inertia of first Drum
%I2*dw2dt=-DEpDafi_2
DEpDafi_2=k*r2*( r1*afi_1-r2*afi_2)+ r2*k(r2*afi_2-q); % DEpDafi_2=diff(Ep,afi_2);
I2=-DEpDafi_2/diff(w2,t); % Moment of inertia of secod Drum
%---END of Values:------------------------------------------------------
%---START of Equation system:---------------------------------------------------
DY1DT = Y(2);
DY2DT = (Mv-(k*r1*(r1*Y(1)-r2*Y(3))))/I1;
DY3DT= Y(4);
DY4DT= (-k*r2*(r1*Y(1)-r2*Y(3))+r2*k*(r2*Y(3)-Y(5)))/I2;
DY5DT = Y(6);
DY6DT = (m*g-r2*k(r2*Y(3)-Y(5)))/m;
%---START of Equation system:---------------------------------------------------
% MAIN FUNCTION:
dyt = [DY1DT; DY2DT; DY3DT; DY4DT; DY5DT; DY6DT]
%use a row for calculations using ODE45 solver:
%[T, Y] = ode45('mokomasis2',[0 10],[0 0 0 0 0 0])
What am I doing wrong? Maybe i'm using a wrong example for solve my equation system? Also i tried to use different combination of system but still get more errors...
  2 comentarios
Rick Rosson
Rick Rosson el 21 de Ag. de 2014
  1. Is this code contained in a single file or multiple files? What are the file names?
  2. What is the exact error message that appears when you run the code?
Tomas
Tomas el 21 de Ag. de 2014
1. Yes in a single file (mokomasis2.m)
2:
>> [T, Y] = ode45('mokomasis2',[0 10],[0 1 1 0 1 1])
Attempted to access diff(1,0); index must be a positive integer or logical.
Error in mokomasis2 (line 8)
diff(q,t) = y(6);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by