Need help with plot

1 次查看(过去 30 天)
Peter Denardo
Peter Denardo 2021-12-17
Having trouble figuring out how to plot my 3 trajectories on a graph for the below program. Your help is appreciated. Thank you.
% All distances and heights measured in meters, time in seconds, velocity in m/s, angles in degrees and
%%acceleration in m/s^2
clear all
clc
H0 = 8;
return_height_tolerance = .001;
theta_0=26;
g=9.81;
dAC=16;
eR=.94 ;
H3=0;
v0=1;
err = 5;
counter=1;
while err>0.008
%Iteration Control
v0 = v0 + .001;
counter=counter+1;
%initial velocities in both directions
v0x=v0*cosd(theta_0); %Trig
v0y=v0*sind(theta_0); %Trig
%Point B = Maximmum height along trajectory path 1
H1=H0+v0y^2/(2*g);
%trajectory path 1
H2=H0+dAC*tand(theta_0)-g/(2*v0x^2)*dAC^2;
%velocities in x and y direction at max height
v1x=v0x; %Zero Acceleration
v1y=(sqrt(v0y^2-2*g*(H1-H0)));
%velocity just prior to hitting wall
v2x=v1x;
v2y=sqrt(v1y^2+2*g*((H0+H1)-(H0+H2)));
v2=sqrt(v2x^2+v2y^2);
%NEW NEW
%H2 = H1 - v2y^2/(2*g);
%velocity just after hitting the wall
v3x=v2x*eR;
v3y=v2y;
v3=sqrt(v3x^2+v3y^2);
theta_3_ref=atand(v3y/v3x); % Trig: Reference Triangle
theta_3_abs=theta_3_ref+180; % Absolute Angle (Quadrant "3")
%velocity just prior to hitting ground
v4x=v3x;
v4y=(sqrt(v3y^2-2*g*(H3-H2)));
v4=sqrt(v4x^2+v4y^2);
theta_4_ref=atand(v4x/v4y);
theta_4_abs=theta_4_ref+180;
%Distance between wall and ground
A=(-g/(2*v3x^2));
B=tand(theta_3_abs);
C=(1/(2*g)*(v4^2-v3^2));
%Quadratic formula for distance between wall and ground
%%based on energy Conservation 2-3 022& Trajectory Eq. 2-3 equations
dCD=(-B+sqrt(B^2-4*A*C))/(2*A);
%trajectory path 2
H3=H2+dCD*tand(theta_3_abs)-g/(2*v4x^2)*dCD^2;
%velocity just after hitting the ground
v5x=v4x;
v5y=v4y*eR;
v5=sqrt(v5x^2+v5y^2);
theta_5_ref=atand(v5x/v5y);
theta_5_abs=theta_4_ref+90;
%distance between ground and return height
dDA=-dAC-dCD;
%trajectory path 3
H4=H3+dDA*tand(theta_5_abs)-g/(2*v5^2)*dDA^2;
%Flight time between point A & B
time_AB=(H1-v0)/-g;
%Flight time between point A & C
time_AC=dAC/v0;
%Flight time between point C & D
time_CD=abs(dCD/v4);
%Flight time between point D & return height
time_D_return=abs(dDA/v5);
%Update Error
err = abs(H4-H0);
%H2=H0+dAC*tand(theta_0)-g/(2*v0x^2)*dAC^2;
%H3=H2+dCD*tand(theta_3_abs)-(g/(2*v3^2*(cosd(theta_3_abs))^2))*dCD^2;
%H4=H3+dDA*tand(theta_5_abs)-(g/(2*v4^2*(cosd(theta_5_abs)^2)))*dDA^2;
end
v0
v0y
v0x
v1y
v1x
v2
v2y
v4
dCD
dDA
H1
H2
H3
H4
time_AB
time_AC
time_CD
time_D_return
counter
  2 个评论
KSSV
KSSV 2021-12-17
What variables you want to plot?
Peter Denardo
Peter Denardo 2021-12-17
I want to plot these 3 trajectories. I solved for the time on each of the trajectories so I am wondering if there is a similar method to plot them over a time to make it neater. H2, H3, and H4 are basically the final y cooridnate.
%H2=H0+dAC*tand(theta_0)-g/(2*v0x^2)*dAC^2;
%H3=H2+dCD*tand(theta_3_abs)-(g/(2*v3^2*(cosd(theta_3_abs))^2))*dCD^2;
%H4=H3+dDA*tand(theta_5_abs)-(g/(2*v4^2*(cosd(theta_5_abs)^2)))*dDA^2;

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2021-12-17
You can store the variables in while loop using:
iwant = zeros([],1) ;
counter=1;
while err>0.008
counter = counter+1 ;
% do alculation for iwant/ update iwant
iwant(counter) = val ;
end
% iwant is an array you can plot here

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fractals 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by