Spring mass system subjected to impulse excitation

4 views (last 30 days)
function [f] = impulse(t,x,h,i)
mu=0.2; wn = 17.1552;
tspan = 0:0.01:1.35;
h = [1 zeros(1,135)];
for i = 1 : length(tspan)
% h(i) = 0 ;
% h(1) = 1 ;
% % hh(i)= 0 + h(i);
% The output is 1 only if the input is 0
% if tspan == 0
% h(i) = 0;
% end
f=zeros(2,1);
f(2) = x(2);
f(1)= -mu*9.81*sign(x(2)) - (wn^2)*x(1) + h(i) ;
end
end
the main problem is the value h(i) is not subtituting in 'f' equation.
The Script file for the above function file is -----
clear all
clc;
clf;
tic;
mu = 0.2;
wn = 17.1552;
tspan=0:0.01:1.35;
x0=[0;0];
[t,x]=ode45(@impulse,tspan,x0);
y = x(:,1);
ydot = x(:,2);
figure(1);
plot(t,y,'r','linewidth',2);
can some one please help me with code for the above equation of motion. I tried a lot but I coudn't finished. I am not good in matlab but this is needed very much. Around 15 days back I posted my code also but I coudn't follow the comments made by few people. Please help me.
  5 Comments
darova
darova on 13 Feb 2020
Please explain what is h(i) ()
DOn't you forgot to divide the entire expression by m?
f(1)= -mu*9.81*sign(x(2)) - (wn^2)*x(1) + h(i) ;
Karthik K
Karthik K on 25 Feb 2020
h(i) is the output of the for loop, to create an array of [1 0 0 0 -----], it has to substitute the element of the array one by one with respect to 't' but it is only substituting the last element of the array.

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 25 Feb 2020
You seem to have misunderstood how matlab integrates ODEs.
Your ODE-function, impulse, should return the derivatives, and , at time t. You put an unnecessary loop in there where you spend plenty of time doing mostly nothing. This is an example of an ODE for a falling body in with some drag:
function dxdtdvxdt = ode_falldrag(t,xv,C)
dxdtdvxdt(1) = xv(2); % dxdt = v, second component of vx
dxdtdvxdt(2) = -9.81 - C*vx(2)*abs(vx(2));
end
Then you can call it something like:
[t,x]=ode45(@(t,x) ode_falldrag(t,x,1.23),tspan,x0);
where I've arbitrarily chosen a random drag-coefficient.
As for how to model impulse, you have to do more of the work. I suggest that you take a look at approximating the Dirac-pulses with Gaussians with decreasing width.
HTH

Community Treasure Hunt

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

Start Hunting!