Can someone help with my code I know MATLAB well I want the code to run and print out a time and height graph.

h

6 Comments

Sorry, my MATLAB doesn't do OCR to turn your image into code. I can't run the image directly. So, you'll have to post the code in your message or attach the m-file with the paper clip icon. In the meantime, look at the fprintf() function.
hello
would be nice if you could precise which variables you want to print out
also I have a doubt that the code is valid , how is t1 calculated ?
i want to do that in matlab i can solve it by hand i just dont know how to solve it using matlab and then print out h and t graph
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.

Sign in to comment.

Answers (1)

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']);

Categories

Find more on Functions in Help Center and File Exchange

Asked:

on 8 Nov 2020

Answered:

on 10 Nov 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!