Need help with plot

1 回表示 (過去 30 日間)
Peter Denardo
Peter Denardo 2021 年 12 月 17 日
コメント済み: 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 Center および File ExchangeFractals についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by