Matlab ode45 help

Trying to graph the solution to an ode using ode45. For some reason my graph is coming out as just a straight horizontal line at 0. Can anyone offer any help?

Function file: named dfeq4

function xdot=dfeq4(t,x)
m = 1;
k = 400;
c = 5;

t1=2;
t2=4;
t3=7;
F0=20;

F1 = F0/t1*t;
F2 = 0;
F3 = F0;

F=F1*stepfun(0,t1)+F2*stepfun(t1,t2)+F3*stepfun(t2,t3);

xdot(1,1)=x(2,1);
xdot(2,1)=-c/m*x(2,1)-k/m*x(1,1)+F/m;
end

Next m file, titled hw114

clear all
close all
clc
x0=[0;0] ;
tspan=[0 10] ;
[t,x]=ode45('dfeq4',tspan,x0) ;
% or in more recent version of MATLAB: [t,x]=ode45(@dfeq,tspan,x0) ;
disp=x(:,1) ;
plot(t,disp)
grid on

My graph is just a straight horizontal line at 0. It shouldn't be. How can I fix this?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories