- #1

- 472

- 14

## Homework Statement

I am trying to create this plot in MatLab

I'm starting out doing the simplest one, no drag, no wind. simple kinematics, right? but I can not get my code to run.

## Homework Equations

Kinematic Equations

## The Attempt at a Solution

Code:

```
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
%%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
%%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
```

whenever I try to plot, I get a linear line. and the graph doesn't even have the correct domain and range or increments. It is weird because I borrowed the code from a previous problem I did, and just changed a bit of it.

I'm certain the problem is probably with my matrices, but I am still new to this. At this point I am just tackling the baseball in a vacuum part of the plot.

#### Attachments

Last edited: