필터 지우기
필터 지우기

Making my simulation stop when z=0

조회 수: 2 (최근 30일)
Stephen Mixon
Stephen Mixon 2019년 10월 28일
댓글: Walter Roberson 2019년 10월 29일
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

답변 (1개)

Walter Roberson
Walter Roberson 2019년 10월 28일
You would use an event function.
I recommend looking at the ballode example, as it does this kind of processing.
  댓글 수: 2
Stephen Mixon
Stephen Mixon 2019년 10월 28일
I looked at the mathworks page for this. How would I implement this in my code
Walter Roberson
Walter Roberson 2019년 10월 29일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by