Question

2. 2052 Write a function in MATLAB called HTBALL to calculate the height of a ball...

2.
2052


Write a function in MATLAB called HTBALL to calculate the height of a ball based on a single input, the elapsed time. The elapsed time will be a single variable in the range of 0 to 6. Predict the value by fitting a 2nd order polynominal to the data points shown below using the polyfit command. Use the command polyval to determine the height of the ball at the inputted time.

timevals=[0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6];

height=[0,46,84,114,136,150,156,154,144,126,100,66,24];

  • Copy and paste the data above into your function
  • The function has 1 input, a single number representing time.
  • You should have a single output equal to the height of the ball based on the curve fit.

Homework Answers

Answer #1

%Please note to save the code as HTBALL.m

%the file should have the same name as function name

%code to calculate height is given below

function height_of_ball=HTBALL(time)
timevals=[0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6];
height=[0,46,84,114,136,150,156,154,144,126,100,66,24];

%here 2 means the 2nd order polynomial fit is done

line = polyfit(timevals,height,2);
height_of_ball=polyval(line,time)

%the rest of the code is to see the fit of the curve

%y1 = polyval(line,timevals);
%figure
%plot(timevals,height,'o')
%hold on
%plot(timevals,y1)
%hold off

%the function should finish with end statement

end

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Homework 3 As you know very well from physics, if you hit a ball forward with...
Homework 3 As you know very well from physics, if you hit a ball forward with a certain angle and a certain speed, it makes an orbital movement. The height of the ball is determined by the equation given below. y(t)=y_0+v_y0 t-1/2 gt^2 Where y0 is the first location of the ball, vy0 is the initial vertical velocity of the ball and g is the gravitational acceleration. After the ball is thrown, the horizontal distance is determined by the following...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except...
*** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an n-by-n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note that...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Given the data set with t values in the first column and y values in the...
Given the data set with t values in the first column and y values in the second column, write a script file that: -Curve fits the given data set with an appropriate polynomial function -Outputs the R2 value of the appropriate fit along with the values of the polynomial order higher and lower (ex. If you choose a 2nd order fit, display the R2 value for first, second, and third order fits.) - Estimate the value of the data at...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Data For Tasks 1-8, consider the following data: 7.2, 1.2, 1.8, 2.8, 18, -1.9, -0.1, -1.5,...
Data For Tasks 1-8, consider the following data: 7.2, 1.2, 1.8, 2.8, 18, -1.9, -0.1, -1.5, 13.0, 3.2, -1.1, 7.0, 0.5, 3.9, 2.1, 4.1, 6.5 In Tasks 1-8 you are asked to conduct some computations regarding this data. The computation should be carried out manually. All the steps that go into the computation should be presented and explained. (You may use R in order to verify your computation, but not as a substitute for conducting the manual computations.) A Random...
Part I. Indicate whether true or false (T or F). ____ Storm water detention ponds typically...
Part I. Indicate whether true or false (T or F). ____ Storm water detention ponds typically are designed to regulate the outflow peak rate at or below a single target value, such as the pre-development (pre-land use change) peak runoff rate for a specified return period event. Detention storage alters the peak but not the volume of the outflow hydrograph. _____ Typical rating curves for weirs are concave upward. Typical rating curves for orifices are concave downward. ____ A sediment...