Trapezium Graphs Plots not Plotting
古いコメントを表示
I'm trying to plot the x and y compoments of an object as the angle between the vertical and the direction of flight inreases from 0 to pi/2. I'm using the trapezium rule, finding the area of each segment to try and plot the speed from the acceleration plot, and also to find the displacement from the speed plot.
But my graphs are only giving me constant values for speed and acceleration as shown below: 

Why are the values of speed and displacement not changing?
This is my code:
t_step_size = 1;
t_start = 89; %s
t_end = 3689;
t_x = 89:1:3689;
t_step_tot = (t_end - t_x(1))/t_step_size;
theta_step = 0.5*pi/t_step_tot;
theta = 0:theta_step:pi/2; %theta increases incrementally according to time
theta_nan = nan(size(theta));
%initial_values
y_double_dot = 2*9.81;
a_y = y_double_dot*cos(theta);
a_y_nan = nan(size(a_y));
v_y = 1765.8;
y = 76.461;
x_double_dot = y_double_dot*sin(theta);
x_double_dot_nan = nan(size(x_double_dot));
x_dot(1) = 0;
x(1) = 0;
theta_t = nan(size(t_x)); % <--- preallocate the output array
for i = 1:length(numel(theta_t))-1
theta = 0:theta_step:pi/2;
x_dot = theta_step*(x_double_dot_nan(i+1) + x_double_dot_nan(i))/2; %horizontal speed
x = theta_step*(x_double_dot(i+1) + x_double_dot(i))/2; %horizontal displacement
v_y = theta_step*(a_y_nan(i+1) + a_y_nan(i))/2;
y = theta_step*(v_y(i+1) + v_y(i))/2;
end
subplot (3,2,1)
plot(t_x,x_double_dot)
xlabel('Time s')
ylabel('a_x')
subplot (3,2,3)
plot(t_x,x_dot,'o')
xlabel('Time s')
ylabel('v_x')
subplot (3,2,5)
plot(t_x,x_dot,'o')
xlabel('Time s')
ylabel('x')
subplot (3,2,2)
plot(t_x,a_y)
xlabel('Time s')
ylabel('a_y')
subplot (3,2,4)
plot(t_x,v_y,'o')
xlabel('Time s')
ylabel('v_y')
subplot (3,2,6)
plot(t_x,y,'o')
xlabel('Time s')
ylabel('y')
grid on
5 件のコメント
David Hill
2022 年 2 月 22 日
You should do your calculations in time. The change in theta is not directly related to the change in time. It is not hard to calculate theta after each time-step. Integrate with respect to time.
Asit Rahman
2022 年 2 月 22 日
David Hill
2022 年 2 月 22 日
I am quite confused. How have you defined your axes? Did you not define your y-axis to be aligned with gravity?
%this shows an example in y-direction only
t_start = 89;
t_end = 3689;
t=t_start:.1:t_end;
y_initial=100000;
vy_initial=0;
ypp=-2*9.81*ones(size(t));
yp=.1*cumtrapz(ypp)+vy_initial;
y=.1*cumtrapz(yp)+y_initial;
plot(t,ypp,t,yp,t,y)
Asit Rahman
2022 年 2 月 22 日
David Hill
2022 年 2 月 22 日
Not true, displacement and velocity are changing, acceleration is constant. I did not plot angle.
回答 (1 件)
Torsten
2022 年 2 月 22 日
x_dot = theta_step*(x_double_dot_nan(i+1) + x_double_dot_nan(i))/2; %horizontal speed
v_y = theta_step*(a_y_nan(i+1) + a_y_nan(i))/2;
Replace the nan-arrays by the correct arrays (x_double_dot_nan by x_double_dot and a_y_nan by a_y).
カテゴリ
ヘルプ センター および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
