Error in ode45 Question
1 view (last 30 days)
Show older comments
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 Comment
Answers (1)
dpb
on 15 Dec 2018
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!