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

1 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2020-1-22
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()

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by