Solving system of second order differential equations

3 次查看(过去 30 天)
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));

采纳的回答

lokender Rawat
lokender Rawat 2018-4-4
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by