Error in ode45 Question

조회 수: 1 (최근 30일)
Simisolaoluwa Adekoya
Simisolaoluwa Adekoya 2018년 12월 15일
편집: dpb 2018년 12월 15일
Please I have tried everthing.
I still cannot get this graph to plot it keeps giving me the error
Error using odearguments
(line 93) @(T,Y)MSSYS(T,Y,M,C,K,B) must return a column vector.
Error in ode45
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_m1 = 400
Code:
m2 = 40
c1 = 12000
c2 = 125
k1 = 80000
k2 = 200000
%%System Parameters
M = [400 0;0 40];
C= [12000 -12000;-12000 12125];
K = [80000 -80000;-80000 280000];
B = eye(2);
[t,y] = ode45(@(t,y) MSsys(t,y,M,C,K,B),[0:0.1: 20],[0 0 0 0])
x1 = y(:,1); x2 = y(:,2);
plot(t,x1,t,x2)
xlabel('Time (seconds)')
ylabel('x_1(t)and x_2(t) (m/sec)')
title('Speed Bump')
%%ODEs
function dydt= MSsys(t,y,M,C,K,B)
A = [zeros(2) eye(2);-inv(M)*K -inv(M)*C];
F = [0 0;200000 125]*0.03*sin(50*t);
dydt = A*y+[zeros(2);inv(M)*B]*F;
end
  댓글 수: 1
dpb
dpb 2018년 12월 15일
편집: dpb 2018년 12월 15일
In future, use the Q? text box to explain the problem; make the title something short like a newspaper headline that highlights the issue. Then use the Code edit button to format the code legibly.
I did for you this time...

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

답변 (1개)

dpb
dpb 2018년 12월 15일
The error message is quite explicit as to at least one problem -- the output from your function MSsys must be a column vector and your's is going to be 4x2 as
A --> 4x4
F --> 2x2
[zeros(2);inv(M)*B] --> 4x2
As the documentation for ode45 says, it must return a vector of the derivatives, one for each equation in the system.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by