Problem tracking a value to plot.

2 ビュー (過去 30 日間)
Chett Manly
Chett Manly 2021 年 10 月 7 日
コメント済み: Jakob B. Nielsen 2021 年 10 月 7 日
Hi, I am trying to plot an accel/decel curve but am struggling to record it. the program seems to run in its two phases but if I try and change V to a vector to follow the program won't run. Apart from that I believe it is correct...
clear; close all; clc
t(1) = 0.001; % time incriment in seconds
C = 0.008; % Drag constant
A = 30; % Accelleration part 1
Ad = -2; % Decelleration part 2
V = 0; % Velocity
N = 1; % iteration ticker
while true % Accel phase
Vnew=(V+t*(A-C*V.^2));
if V > 60
break
end
V = Vnew;
N = N+1;
end
while true % Decel phase
V=(Ad-C*V.^2);
if V < 0
break
end
V = Vnew;
N = N+1;
end
plot(V);

採用された回答

Jakob B. Nielsen
Jakob B. Nielsen 2021 年 10 月 7 日
You have a problem with indexing. Every time you say V=Vnew, your V is simply replaced with a new overwritten value. You have an iteration ticker you call N, use it!
Now, your Decel phase has no time factor associated with it, so you'll need to look at that. Right now your test subject accelerates to a full stop in one iteration. Imagine the forces involved :D
clear; close all; clc
t(1) = 0.001; % time incriment in seconds
C = 0.008; % Drag constant
A = 30; % Accelleration part 1
Ad = -2; % Decelleration part 2
V = 0; % Velocity
N = 1; % iteration ticker
while true % Accel phase
Vnew=(V(N)+t*(A-C*V(N)^2));
if Vnew > 60
break
end
N = N+1;
V(N) = Vnew;
end
while true % Decel phase
Vnew=(Ad-C*V(N)^2); %get your timing into this term
if Vnew < 0
break
end
N = N+1;
V(N) = Vnew;
end
plot(V);
  2 件のコメント
Chett Manly
Chett Manly 2021 年 10 月 7 日
I was close... I tried what you did but missed out a step. I kept getting this fault.
Index exceeds the number of array elements (1).
Yes that is a sudden stop in the last frame... the formula is the same for the slowdown so I ended up with this. It follows on but not sure the curve is right but can probably sort it out.
clear; close all; clc
t(1) = 0.001; % time incriment in seconds
C = 0.008; % Drag constant
A = 30; % Accelleration part 1
Ad = -2; % Decelleration part 2
V = 0; % Velocity
N = 1; % iteration ticker
while true % Accel phase
Vnew=(V(N)+t*(A-C*V(N)^2));
if Vnew > 60
break
end
N = N+1;
V(N) = Vnew;
end
while true % Decel phase
Vnew=(V(N)+t*(Ad-C*V(N)^2)); %get your timing into this term
if Vnew < 0
break
end
N = N+1;
V(N) = Vnew;
end
plot(V);
Jakob B. Nielsen
Jakob B. Nielsen 2021 年 10 月 7 日
At least you have something to go by now :) have fun with it! :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by