Solving system of second order differential equations
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
karthik madhamshetty
el 30 de Mzo. de 2018
Comentada: Torsten
el 4 de Abr. de 2018
Hi,
I tried to solve a system of coupled differential equations.
Can anyone help me with this error?
"Error using odearguments (line 93) ODE_FUNCTION must return a column vector.
Error in ode23tb (line 135) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ODE_Function_Solver (line 4) [t,y] = ode45(@ODE_Function,tspan,y0);"
Thank you.
tspan = 0:0.001:2;
y0 = [0 0;0 0;0 0;0 0;0 0;0 0];
[t,y] = ode23tb(@ODE_Function,tspan,y0);
function dydt = ODE_Function(t,y)
m1 = 1;
k1 = 100;
m2 = 1;
k2 = 100;
w = 2*pi*50;
F = sin(w*t);
h = 0.1;
w = 0.1;
% First ODE
dydt(1) = y(2);
dydt(2) = F - k1/m1*(y(1)-y(5))-2*k2/m1*cos(atan((2*h-2*y(3))/w))*(y(1)-y(3));
% SecondODE
dydt(3) = y(4);
dydt(4) = -2*k2/m2*cos(atan((2*h-2*y(3))/w))*(y(3)-y(1));
% Third ODE
dydt(5) = y(6);
dydt(6) = -k1/m1*(2*y(5)-y(1)-y(9))-2*k2/m1*cos(atan((2*h-2*y(7))/w))*(y(1)-y(3));
% Fourth ODE
dydt(7) = y(8);
dydt(8) = -2*k2/m2*cos(atan((2*h-2*y(7))/w))*(y(7)-y(5));
% Fifth ODE
dydt(9) = y(10);
dydt(10) = -k1/m1*(y(9)-y(5))-2*k2/m1*cos(atan((2*h-2*y(11))/w))*(y(1)-y(3));
% Sixth ODE
dydt(11) = y(12);
dydt(12) = -2*k2/m2*cos(atan((2*h-2*y(11))/w))*(y(11)-y(9));
0 comentarios
Respuesta aceptada
lokender Rawat
el 4 de Abr. de 2018
The return type of the parameter from the function block must be a column vector. So, you can add the below statement at the end, inside the function block:
dydt=dydt';
I think you were missing this.
1 comentario
Torsten
el 4 de Abr. de 2018
... and you shouldn't supply y0 as a (6x2) matrix, but as a (12x1) vector.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!