MATLAB: Peoblem in solving 2nd order differential equation by ode45

siva srinivas kolukula

I want to calculate the displacement of a structure fitted with a friction damper for Elcentro ground excitation.The damping force will act to resist the displacement of the structure if (2εwv+w^2u)exceeds damper force fs(fs=known value,v=velocity,u=displacement,ε=damping ratio),and i am interested to find the final time vs displacement curve of the structure.the equation of motion for without damper case a+2εwv+w^2u+ag=0 and withdamper case a+2εwv+w^2u+ag=0(a=accleration of the building,ag=Elcentro earthquake excitation input)
  • _ code in matlab_*
load EINS.dat ; % load the Seismic data
t = EINS(:,1) ; % time intervel
a = EINS(:,2) ; % acceleration for respective time step
a = a*9.8 ; % Changing Acceleration to m/s/s
%--------------------------------------------------------------------------

% Plot the Response of a SDOF system fitted with friction damper to the Seismic input
%--------------------------------------------------------------------------
xi = 2/100 ; % Relative damping
Tn = 1; % Natural period of SDOF system
y0 = [0;0] ;
fs=2;% Initial Conditions
% Response of SDOF System
% if abs((4*pi*xi/Tn)*Y(i-1,2)-(2*pi/Tn)^2*Y(i-1,1))<fs
[t,Y] = ode45(@odefun,t,y0,[],xi,Tn,t,a) ;
and the subprogram odefun is,
function ydot = odefunnn(t,y,xi,Tn,t1,a2)
a = interp1(t1,a2,t) % Interpolate the data set (t1,a2) at time t
Y=zeros(3001,2);
i=2
if abs((4*pi*xi/Tn)*Y(i-1,2)-(2*pi/Tn)^2*Y(i-1,1))>2
ydot = [y(2); -(4*pi*xi/Tn)*y(2)-(2*pi/Tn)^2*y(1)-2-a]
else
ydot = [y(2); -(4*pi*xi/Tn)*y(2)-(2*pi/Tn)^2*y(1)- a]
end
i=i+1
but the program is not running,may be because the logic is not correct…plz help me and it is showing the following errors,
Undefined function 'Y' for input arguments of type 'double'.
Error in odefunnn (line 9) if abs((4*pi*xi/Tn)*Y(i-1,2)-(2*pi/Tn)^2*Y(i-1,1))>1
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, …
Error in frictiondampertest (line 33) [t,Y] = ode45(@odefunnn,t,y0,[],xi,Tn,t,a) ;

Best Answer

Hello...the code works fine, you have to change
[t,Y] = ode45(@odefun,t,y0,[],xi,Tn,t,a) ;
to
[t,Y] = ode45(@odefunnn,t,y0,[],xi,Tn,t,a) ;
or rename the function odefunnn.m to odefun.m. The result is as attached...