Effacer les filtres
Effacer les filtres

Solving system of second order differential equations

3 vues (au cours des 30 derniers jours)
karthik madhamshetty
karthik madhamshetty le 30 Mar 2018
Commenté : Torsten le 4 Avr 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));

Réponse acceptée

lokender Rawat
lokender Rawat le 4 Avr 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 commentaire
Torsten
Torsten le 4 Avr 2018
... and you shouldn't supply y0 as a (6x2) matrix, but as a (12x1) vector.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by