Can someone help with my code I know MATLAB well I want the code to run and print out a time and height graph.
1 view (last 30 days)
Show older comments
6 Comments
Image Analyst
on 10 Nov 2020
Attach your m-file with the paper clip icon. Or else just copy from MATLAB and paste back here in your reply, then highlight it and click the code icon.
Answers (1)
Mathieu NOE
on 10 Nov 2020
so -- after several corrections, we hav something
see below
Also I noticed in the hand paper you have swapped the initial values for V1x and V1y
clc;
close all;
clear all;
%User Input
h_person_in = (51.3/12);% HEIGHT in inches times .75 then converted to feet
v1 = 10; %ft/s current velocity
theta_deg = 15; %degrees
e = .8; %coefficient of restitution
x = 6.10 % ft length of where i want the ball to land
g = 32.2 % ft/s^2
t =0 % starting time (initial conditions)
% v1y = v1*sin(theta_deg);
% v1x = v1*cos(theta_deg);
v1y = v1*sin(theta_deg*pi/180); %correction
v1x = v1*cos(theta_deg*pi/180); %correction
% v1y^2 == v1y^2+(2*-g*h_person_in)
v1y_squared = v1y^2+(2*g*h_person_in); % correction
v1y = sqrt(v1y_squared); % missing line
v2 = sqrt((e*v1y)^2+v1x);
% solve for t1 (second order equation)
% h_person_in = v1y*t1+(.5*g*t1^2)
% reorgainzed like : ax² + bx + c = 0
a = .5*g;
b = v1y;
c = - h_person_in;
% determinant : delta = b² -4*a*c
delta = b^2 -4*a*c;
% solution (positive) : sol = (-b+sqrt(delta)) / (2*a)
t1 = (-b+sqrt(delta)) / (2*a);
theta_deg2 = 180/pi*atan((e*v1y)/v1x); % correction
x1= v1x*t1;
x2= x-x1;
% tf= v1x/x2; % time cannot be velocity / distance it's the contrary
tf= x2/v1x; %
% display (example) in command window
disp([' time t1 is : ' num2str(t1) ' seconds']);
disp([' time tf is : ' num2str(tf) ' seconds']);
0 Comments
See Also
Categories
Find more on Environment and Settings 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!