Question
Can someone help me change this code into one that addresses this question? It's Matlab The code from the lab didnt fully work but i
Can someone help me change this code into one that addresses this question? It's Matlab
The code from the lab didnt fully work but i just need help fixing it up for the assignment
Task 6 (25 points) In this weeks lab, you were asked to create a script throwBall.m. Here, turn the code from a script into a function named throwBall_func.m. The function takes three arguments v, theta and maxTime as inputs and returns a logical value (true or false), depending on whether the ball hits the ground in the allowed time or not. Here is an example of a function call: >> isTrue = throwBall_func(v, theta, maxTime) While testing the script for Lab 3, you were asking the user to input values for v and theta. You probably noticed that for certain values of v and theta the ball did not hit the ground in 20 seconds. Here you are evaluating whether the ball will hit the ground in maxTime seconds. If none of the values calculated for height (the vector y) are negative, your call to the function find will return an empty vector. Use this fact to figure out whether the ball hits the ground in the allowed time or not. Assign to the return argument variable the appropriate logical value (true if ball hits the ground within allotted time, false otherwise). Note: you must do this WITHOUT using selection statements (IF-ELSE). Hint: you might want to investigate the function isempty().
Heres the code from the lab clear all close all
%define x values (range value from 1 to 20 %type x and y values into X = 0:20;
%define the constants %initial height of ball trajectory in meters h=1.5 ;
%g = force of gravity g=9.8;
%prompt the user to enter in values %v = initial velocity at time of release %prompt user to input the initial velocity v = input('Enter initial launch velocity in meters per seconds: ')
%prompt user to input the initial angle of release (theta) angle = input('Enter initial angle of release in degrees: ') %initial angle at the time of release (degrees)
%time vector t = linspace(0, 20, 1000);
%call the function to find x(t) x = ballfunction1(v,angle);
%call the function to find y(t)
y=ballfunction2(v,angle);
t_hit=find(y<=0); y_hit=y(t_hit); x_hit=x(t_hit(0)); fprintf('The ball hits the ground at a distance of %f meters',x_hit) t_hit=t_hit(0);
%plot figure figure hold on title ('Trajectory of the ball') plot(x,y) plot(x,y.*0,'k-') xlabel('Distance (m)') ylabel('Ball height (m)')
plot([0:0.01:max(x)],[0:max(x)/0.01:0],'--','LineWidth',2.0,'Color','k')
Step 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