How can I use 'if statement' in ode function?
Mostrar comentarios más antiguos
I want to simulate bouncing ball in 2m horizontal plate(neglect gravity, radius=0.02m, m=0.025kg).
And I want to consider damping condition when ball contact wall(x=0, x=2m).
==============================
function dx = HW6_1(t,x)
dx = zeros(2,1); % a column vector
dx(1) = x(2);
R=0.02;
m=0.025;
fd=0.01;
f0=50;
d=min(x(1),2-x(1));
delta=R-min(R,d);
if 0<x(1)<0.02
dx(2)=(f0*tan(pi*delta/(2*R))-fd*x(2))/m;
elseif 1.98<x(1)<2
dx(2)=(-f0*tan(pi*delta/(2*R))-fd*x(2))/m;
else
dx(2)=0;
end
-----------------------------------------------
[T,X] = ode45(@HW6_1,0:0.001:3,[1 5]);
plot(T,X(:,1))
title('Pro no.1')
xlabel('time(s)')
ylabel('x')
=============================================
However matlab doesn't read the 'if statement'
How can I use 'if statement' in ode function?
Respuestas (1)
Torsten
el 23 de Mayo de 2016
Use
if (a<b) && (b<c)
instead of
if a<b<c
Best wishes
Torsten.
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!