Error in ode45 Question

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 个)

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.

类别

产品

版本

R2018b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by