how to solve non linear differential equation with sign function
Afficher commentaires plus anciens
I have to solve the equation of the motion of a rigid block subjected to a horizontal base excitation ag. The equation of the motion is:
a + nk*g*sign(v) = - ag
a=acceleration of the block, nk=friction coefficient, g=gravity acceleration, v=velocity of the block, ag=horizontal base excitation
I am trying to solve it by ODE45 solver but because of the sign function it doesn't work: I have wrong results. I would like to know how to solve this kind of equation on Matlab. Thank you so much!
FUNCTION:
function xdot = sliding(a,x)
n=size(a);
nk = 0.3; % friction coefficient
g = 9.810; % Gravitational constant in m/sec^2
for i=1:n(1)
xdot = [x(2);
-a(i,1)-nk*g];
end
SCRIPT:
a=0:0.1:4; %acceleration
t=0:0.1:4; %time
a=[a' t'];
x0 = [0; 0]; %initial condition
[t,x] = ode45('sliding',a(:,2),x0);
plot(t,a(:,1),'-');
xlabel('time'); ylabel('a(t)'); title('a (t)');
figure;
plot(t,x(:,1),'-'); xlabel('time'); ylabel('y_{1}(t)'); title('x (t)');
figure;
plot(t,x(:,2),'-'); xlabel('time'); ylabel('y_{2}(t)'); title('d x / dt (t)');
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Assembly dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!