Hey i'm trying to simulate a bouncing ball but i wasn't able to simulate it on viscircles function. i get Dimensions of matrices being concatenated are not consistent. problem everytime
Afficher commentaires plus anciens
if true
function main
global chart;
chart = 0;
tspan = [0,15];
initial_conditions = [100 0];
options = odeset('events',@events, 'RelTol', 1e-5, 'MaxStep',1e-2);
hold on;
durum = 0;
while durum ~= 1
[t,z] = ode45(@bouncing,tspan,initial_conditions,options);
if chart == 0
disp('tochdown');
%plot(t,z(:,1),'b');
viscircles([3,z(:,1)],5);
else
disp('liftup');
%plot(t,z(:,1),'r');
viscircles([3,z(:,1)],5);
end
if t(end) == tspan(2) durum =1 ; else tspan(1) = t(end);
end chart = 1 - chart; initial_conditions = z(end,:); end
end
function dz = bouncing(t,z) global chart; dz = zeros(2,1); g = 9.81; k = 40; c = 1; m = 1; switch chart case 1 dz(1) = z(2); dz(2) = g-k*z(1)-c*z(2);
case 0
dz(1) = z(2);
dz(2) = -g;
end
end
function [value, isterminal, direction] = events(t,z) global chart; switch chart case 1 value = z(1); isterminal = 1; direction = 1;
case 0
value = z(1);
isterminal = 1;
direction = -1;
end
end
end
1 commentaire
daniel parker
le 27 Juin 2015
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming 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!