Making my simulation stop when z=0
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!