필터 지우기
필터 지우기

Solving system of second order differential equations

조회 수: 3 (최근 30일)
karthik madhamshetty
karthik madhamshetty 2018년 3월 30일
댓글: Torsten 2018년 4월 4일
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.
  댓글 수: 1
Torsten
Torsten 2018년 4월 4일
... and you shouldn't supply y0 as a (6x2) matrix, but as a (12x1) vector.

댓글을 달려면 로그인하십시오.

추가 답변 (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