[T,Z] = ode45(@bouncing, [0 12], [100 0],'tspan','options','events');
options = odeset('events');
events(t,z) = [y(1)-10,1,-1]
value = y(1)-10;
isterminal = 1;
direction = -1;
axis([-5 5 0 120])
a = 0;
y = Z(:,1);
while a < 69
viscircles([0,y(1+a)],10,'Linewidth',10');
pause(0.1);
cla;
a = a+1;
end

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Jun. de 2015

1 voto

events = @(t,y) [y(1)-10, 1, -1];
options = odeset('events', events);
[T,Z] = ode45(@bouncing, [0 12], [100 0], options);
axis([-5 5 0 120])
y = Z(:,1);
for a = 1 : 69
viscircles([0,y(a)],10,'Linewidth',10');
pause(0.1);
cla;
end
However, I do not see any reason to assume you will get at least 69 results. It would make more sense to use length(y) instead of 69.

3 comentarios

daniel parker
daniel parker el 25 de Jun. de 2015
Editada: Walter Roberson el 25 de Jun. de 2015
because i have 69 columns i used it. thank you for your comment but when i try to perform your the code i get this error
Error in deneme (line 3)
[T,Z] = ode45(@bouncing, [0 12], [100 0], options);
did i called the function wrongly ? this is my bouncing function code
function dz = bouncing(t,z) %situation 0
dz = zeros(2,1);
g=10;
dz(1) = z(2);
dz(2) = -g;
second error is that
Error using feval
Output argument "varargout{2}" (and maybe others) not assigned during call to "@(t,y)[y(1)-10,1,-1]"
Walter Roberson
Walter Roberson el 25 de Jun. de 2015
function deneme
options = odeset('events', @bb_events);
[T,Z] = ode45(@bouncing, [0 12], [100 0], options);
axis([-5 5 0 120])
y = Z(:,1);
for a = 1 : length(y)
viscircles([0,y(a)],10,'Linewidth',10');
pause(0.1);
end
end
function dz = bouncing(t,z) %situation 0
dz = zeros(2,1);
g=10;
dz(1) = z(2);
dz(2) = -g;
end
function [value, isterminal, direction] = bb_events(t, y)
value = y(1)-10;
isterminal = 1;
direction = -1;
end
daniel parker
daniel parker el 25 de Jun. de 2015
thank you :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Jun. de 2015

Comentada:

el 25 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by