Filter löschen
Filter löschen

Making my simulation stop when z=0

2 Ansichten (letzte 30 Tage)
Stephen Mixon
Stephen Mixon am 28 Okt. 2019
Kommentiert: Walter Roberson am 29 Okt. 2019
I need a way to tell my plot to stop when z=0. Right now it keeps going into the negative z direction until it hits my time that I have it set to. Here is my code
tspan = [0, 30];
IC = [0, 91.8559, 0, 91.8559, 0, 86.6025]
[time, state_values] = ode45(@project12,tspan,IC);
x = state_values(:,1);
xdot = state_values(:,2);
y = state_values(:,3);
ydot=state_values(:,4);
z = state_values(:,5);
zdot=state_values(:,6);
%plot x(t)
subplot(3,1,1)
plot(time,x)
%plot y(t)
subplot(3,1,2)
plot(time,y)
%plot z(t)
subplot(3,1,3)
plot(time,z)
function sdot = project12(t,s)
% s eqauls x, xdot, y, ydot, z, zdot
sdot(1)=s(2)
sdot(2)=0
sdot(3)=s(4)
sdot(4)=0
sdot(5)=s(6)
sdot(6)=-9.81
sdot=sdot'
end

Antworten (1)

Walter Roberson
Walter Roberson am 28 Okt. 2019
You would use an event function.
I recommend looking at the ballode example, as it does this kind of processing.
  2 Kommentare
Stephen Mixon
Stephen Mixon am 28 Okt. 2019
I looked at the mathworks page for this. How would I implement this in my code
Walter Roberson
Walter Roberson am 29 Okt. 2019
Copy ballode to a new file . Change the function name on the first line. Change
for i = 1:10
to
for i = 1:1
Change function f to your actual function.
That should pretty much do it.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by