Particle Velocity. Trying to solve for v0 with loops/conditional statements
Show older comments
Disclamier: I am really bad at Matlab. Please go easy on me :)
Problem: I am given a final distance (8.9m), and I want to solve for initial velocity
Approach: I want to use loops/conditionals to solve for the problem. I know it's not the most elegant approach, but this problem is driving me crazy. I would like to increment velocity during each while loop, then check the final value of distance against my given distance (8.9m). If my distance from the while loop is too low, then I would like to increment v0 by 0.01, and run the loop again. When the distance from the while loop equals my given distance, then I have my v0.
I have a good working while loop to figure out the distance from a given v0; however, I am having a hard time incrementing v0 in a way that doesn't put my computer in an infinite loop or returns poor results.
Here's my code:
% Prepare Workspace
clear; % Clears variables from the workspace
clc; % Clears the command window
clf; % Clears current figure window
% Define variables and constraints
g=9.81; %gravity
m=80; % mass
Cd= 0.72; %coefficent of drag
A = 0.5; % cross-sectional area
theta=pi/8; %22.5 deg
v=11.1; %inital velocity
dt=0.0001; %change in time / time step
% Control Jump 1 Data
rho1=0.94; %kg/m^3
D1=.5*Cd*rho1*A;
x1=zeros(1,10000); %x axis index Jump 1
y1=zeros(1,10000); %y axis index Jump 1
t1=zeros(1,10000); %time index Jump 1
xdot=v*cos(theta); % problem description
ydot=v*sin(theta); % problem description
%While loop Control Jump 1 rho 0.94
i=1;
L1=0;
if L1<8.9
v=v+0.01;
x1=zeros(1,10000); %x axis index Jump 1
y1=zeros(1,10000); %y axis index Jump 1
t1=zeros(1,10000); %time index Jump 1
while min(y1)>-0.001
ax1= -(D1/m)*(xdot^2+ydot^2)^0.5*xdot;
ay1= -g-(D1/m)*(xdot^2+ydot^2)^0.5*ydot;
xdot=xdot+ax1*dt;
ydot=ydot+ay1*dt;
x1(i+1)=x1(i)+xdot*dt+.5*ax1*dt^2;
y1(i+1)=y1(i)+ydot*dt+.5*ay1*dt^2;
t1(i+1)=t1(i)+dt;
i=i+1;
end
L1=max(x1); %Length of Jump 1
T1=max(t1); %Time of Jump 1
Y1=max(y1); %Vertical Height of Jump 1
i=1;
end
Thanks for any help!!
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!