Question
what is wrong with my MatLab code? I am trying to get the middle line of this plot. the one without wind nor drag but
what is wrong with my MatLab code?
I am trying to get the middle line of this plot. the one without wind nor drag
but my plots are a complete failure.
What is wrong?
close all
clear all
clc
%%defining variables
tMin = 0 %seconds
angleWithHorizontal = 35 %degrees
initialVelocity = 100 * .44704 %converting mph to m/s
tailWind = 10 * .44704 %converting mph to m/s
headWind = 10 *.44704 %converting mph to m/s
gravity = -9.8 %m/s^2
dt = .1 %change in time
mass = 1%unknown
initialVelocityY = initialVelocity * sin(angleWithHorizontal)
initialVelocityX = initialVelocity * cos(angleWithHorizontal)
timeToMaxHeight = -initialVelocity / gravity
tMax = 2*timeToMaxHeight
initialPositionX = 0
initialPositionY = 0
accelerationX = 0
distanceTraveledX = initialPositionX + initialVelocityX * tMax + .5 * accelerationX * tMax^2
%dragCoefficient = .5
%airDensity = 1.225 %kg/m^3
%surfaceArea = .33 %in Meters Squared
%%Position in Space Without Drag nor Wind
t = tMin:dt:tMax; % time steps
[j,k] = size(t);
velocityWithoutDrag(1) = initialVelocityY;
positionX(1) = initialPositionX;
positionY(1) = initialPositionY;
% calculate instantenous speeds and position
for i = 2:k
velocityWithoutDrag(i) = velocityWithoutDrag(i-1) + (gravity*dt)
positionX(i) = positionX(i-1) + velocityWithoutDrag(i)*dt + .5*gravity*dt^2
positionY(i) = positionY(i-1) + velocityWithoutDrag(i)*dt + .5*gravity*dt^2
end
%%Velocity With Drag
%currentTime = tMin:dt:tMax; % time steps
%[x,y] = size(currentTime);
%velocityWithDrag(1) = vmin;
% calculate instantenous speeds
%for i = 2:y
%velocityWithDrag(i) = velocityWithDrag(i-1) + ((power.*dt)./(mass.*velocityWithDrag(i-1)))-((dragCoefficient.*airDensity.*surfaceArea.*velocityWithDrag(i-1)^2)/(mass));
%end
%%Plots
figure(1)
hold on
box on
plot(positionX,positionY,'-k')
set(gca,'Xtick',linspace(0,150,4),'fontsize',18,'Ytick',linspace(0,30,4))
set(gcf,'Color','w');
set(gcf,'Resize','on');
hold off
edit: asked to list the formulas. For a ball moving through space without any drag, it should just be the kinematic equations. which are:
X = X_o + V_o*t + 1/2*a*t^2
V = V_o + a*t
Trajectory of a batted basebal 30 tailwind 20 no wind 10 headwind 0 0 50 100 150 x (m) Figure 2.7: Calculated trajectory of a baseball hit at an initial velocity of 110 mph, with the effects of atmospheric drag included. Solid curve: no wind; dotted and dot-dashed curves: a tailwind and headwind of 10 mph. In all cases we assume that the initial velocity makes an angle of 35 with the horizontal. Trajectory of a batted basebal 30 tailwind 20 no wind 10 headwind 0 0 50 100 150 x (m) Figure 2.7: Calculated trajectory of a baseball hit at an initial velocity of 110 mph, with the effects of atmospheric drag included. Solid curve: no wind; dotted and dot-dashed curves: a tailwind and headwind of 10 mph. In all cases we assume that the initial velocity makes an angle of 35 with the horizontalStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started