I couldn't substitute the values of the for loop to the ode

can some one please help me code for this equation of motion of the spring mass system subjected to unit impulse. I tried a lot bus i coudn't solve the errors. The code what i written is given below.
function f = impulse(t,x)
mu=0.2;
wn = 17.1552;
f=zeros(2,1);
f(1) = x(2);
f(2)= -mu*9.81*sign(x(2)) - (wn^2)*x(1) + f(i) ;
end
clear all;
clc;
clf;
tic;
mu = 0.2;
wn = 17.1552;
tspan=0:0.001:1.35;
for i = 1 : length(tspan)
f(i) = dd1(tspan(i));
end
x0=[0;0];
[t,x]=ode45(@impulse,tspan,x0);
y = x(:,1);
ydot = x(:,2);
figure(1);
plot(t,y,'r','linewidth',2);

1 Comment

What is dd1? Why do you initialize f when you do not use f afterwards?
That sign() in impulse() introduces a discontinuity in the derivative of the equations. None of the ode*() routines can deal with discontinuities in the derivatives. You will need to introduce an event function to detect the change in sign of x(2) and signal to terminate the integration and then restart. I recommend that you look at the example named ballode()

Sign in to comment.

Answers (0)

Asked:

on 22 Jan 2020

Commented:

on 22 Jan 2020

Community Treasure Hunt

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

Start Hunting!