Change in Speed & Acceleration
9 ビュー (過去 30 日間)
古いコメントを表示
Developing an algorithm to plot a cars plan in regards to acceleration and velocity.
speed: -20km/h +20km/h
What I have:
%constants
d1 = 28;
d2 = d1;
m = 2;
F = 6;
Vmax = 3;
%acceleration
a=F/m;
Acceleration=a
%Time
t=d1/Vmax;
Time=t
%speed
S=d1/Time;
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
%velocity
v=a*T;
x=T;
plot(x,S,'-.dr');
yyaxis left
xlabel('Time')
ylabel('Speed')
title('Car Plan')
yyaxis right
plot(x,v);
ylabel('Distance')
Output:
What I'm looking for:
How do I go about adding a rate of change for both my acceleration and velocity?
3 件のコメント
James Tursa
2021 年 11 月 18 日
編集済み: James Tursa
2021 年 11 月 18 日
@Adam Danz I think "speed: -20km/h +20km/h" means the velocity varies between -20 km/h and +20 km/h ???
And the whiteboard figure doesn't make sense to me either ...
Adam Danz
2021 年 11 月 18 日
Hmmm then it would appear that the direction changes assuming that's what the sign of the speed is. And I'm assuming this is linear speed rather than angular. A lot of unknowns here.....
回答 (1 件)
prabhat kumar sharma
2024 年 4 月 4 日
Hi Andrei,
It looks like you're having trouble getting your calculations to match up with what you expected based on a handwritten plot about a car's speed, how fast it's speeding up (acceleration), and time. To help fix this mismatch and get your results to look more like your original plot, check out the code below. This specific code is meant to make it easier for you to plot how a car's speed and acceleration change over time, aiming to solve the main problems you're facing:
% Constants
Vmax_kmh = 10; % Maximum speed in km/h
Vmax = Vmax_kmh * (1000/3600); % Convert Vmax to m/s
ta = 5; % Time to reach max speed, adjust as needed
tm = 10; % Time maintaining max speed, adjust as needed
% Initial Acceleration value, ensuring it's higher than Vmax
A_initial_value = Vmax * 2.5; % Example: 2.5 times the Vmax
A_final_value = 1; % Final constant acceleration value
% Time arrays for each phase: acceleration, maintaining speed, deceleration
T_accel = linspace(0, ta, 100); % 100 points for smooth plotting
T_maintain = linspace(ta, ta+tm, 100);
T_decel = linspace(ta+tm, 2*ta+tm, 100);
% Speed profiles
V_accel = (Vmax/ta) * T_accel; % Linear increase
V_maintain = Vmax * ones(size(T_maintain)); % Constant speed
V_decel = Vmax - (Vmax/ta) * (T_decel - ta - tm); % Linear decrease
V_total = [V_accel, V_maintain, V_decel]; % Combine for plotting
T_total = [T_accel, T_maintain, T_decel];
% Define acceleration profile - [const, decrease continuously, const at 1]
A_const_initial = A_initial_value * ones(size(T_accel)); % Constant initial acceleration
A_decrease = linspace(A_initial_value, A_final_value, numel(T_maintain)); % Decreasing acceleration to final constant value
A_const_final = A_final_value * ones(size(T_decel)); % Constant final acceleration
A_total = [A_const_initial, A_decrease, A_const_final]; % Combine
T_total_accel = [T_accel, T_maintain, T_decel]; % Time array for acceleration plot
% Plot Velocity and Acceleration Profile on the same figure
figure;
yyaxis left;
plot(T_total, V_total, 'b-', 'LineWidth', 2);
ylabel('Speed (m/s)');
yyaxis right;
plot(T_total_accel, A_total, 'r--', 'LineWidth', 2);
ylabel('Acceleration (m/s^2)');
xlabel('Time (s)');
title('Car Speed and Acceleration Profile');
grid on;
I hope it helps !
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!