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

조회 수: 1 (최근 30일)
Karthik K
Karthik K 2020년 1월 22일
댓글: Walter Roberson 2020년 1월 22일
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