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
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 Center 和 File 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!