Projectile Motion with analytical and numerical analysis.
Afficher commentaires plus anciens
Can someone help me fix the function? My last plot isn't plotting the curve.
%% HW3 Projectile Motion
clear; clc
%% Experimental
a=-9.8; %gravity
n=1; %interval
tt=10; %total time
T=0:n:tt; %time
% equation
x=T;
yy=a*(T); %F=m*a(t) neglecting mass
%% Analytic Analysis
% falling object without any drag coefficient and air density
%graph Velocity vs. Time
%% inputs
h=1; %step size
tl=0; %lower bound
th=10; %upper bound
vg=100; %initial velocity of golf ball (m/s)
%% establish domain
t=[tl:h:th]; %independent variable (time)
v= zeros(1,length(t)); %dependent variable (velocity)
%% initial condition
y(1)=vg;
%% constants
mg=1; %mass of golf ball
g=-9.8; %gravity
%% define function ODE
f=@(t,y) mg.*g; %Newton's Second Law equation is f=m.*a
%loop over N
for i=1:length(t)-1
% t(i+1)=t(i)+h; %Euler's Method
y(i+1)=y(i)+f(t(i),y(i)).*h;
end
%% Numerical Analysis
%consist of air density, cross sectional area, and Drag Coefficient of
%object
%% inputs
h=0.5; %step size
tl=0; %lower bound
th=10; %upper bound
vg=100; %initial velocity of golf ball (m/s)
%% establish domain
t=[tl:h:th]; %independent variable (time)
v= zeros(1,length(t)); %dependent variable (velocity)
%% initial condition
y(1)=vg;
%% constants
mg=2; %mass of golf ball
g=-9.8; %gravity
rho=1.225; %air density
Cg=0.47; %drag coefficient of a sphere
Ag=0.005; %cross-sectional area of golf ball
%% define function ODE
f=@(t,y) mg.*g; %Newton's Second Law equation is f=m.*a
%loop over N
for i=1:length(t)-1
% t(i+1)=t(i)+h; %Euler's Method
y(i+1)=y(i)+f(t(i),y(i)).*h;
end
fn=@(t,y) ((1/2.*mg).*(rho).*(Cg).*(Ag).*(vg.^2))+g;
for i=1:length(t)-1
yn(i+1)=y(i)+fn(t(i),y(i)).*h;
end
%% Plots
figure(1); clf(1)
plot(x,yy,'-.dr');
hold on
plot(t,y,'-o')
hold on
plot(t,yn,'--x')
title('Experimental and Analytic Analysis of a falling golf ball')
xlabel('Time (s)')
ylabel('Velocity (m/s)')
xlim([0 20])
ylim([0 25])

1 commentaire
Image Analyst
le 15 Sep 2021
Modifié(e) : Image Analyst
le 15 Sep 2021
Need more detail. Exactly which variable (yy, y, or yn) is not plotting?
Why is the x axis x for one plot but t for the other two plots?
You don't need clf(1) right after you call figure(1) -- it's already clear/blank!
If you get rid of the calls to xlim and ylim, the plot looks like this:

Réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!