Question

In: Computer Science

Part-1. Write a matlab code to find the height of the tallest guy in a basketball...

Part-1. Write a matlab code to find the height of the tallest guy in a basketball team (including bench, i.e., 22 players). Their height is stored in array variable H. If they are more than one player representing the tallest the program should report either height as the tallest. Use an efficient algorithm. Size the array H (find the number of elements) with the function size() in the numpy module (e.g., np.size(). Algorithm should work for any number of players.

Part-2. Write a user-defined python function to find the heigth of the tallest and use it in a driver program. Generate a ‘fake’ data using the following statements:

import numpy as np
N=22 # for 22 players

# 1D array of float numbers within 5.5 to 8.0 feet H= np.random.uniform(5.5, 8.0, size=(1,N)) print("random float array in [5.5, 8.0] \n", H,"\n")

Also, I’d like a python code for the same excersice.

Solutions

Expert Solution

Python code

Screenshot

Program

import numpy as np
def tallestHeight(heights):
    #Set first element as maximum height
    max=heights.flat[0]
    #Traverse each element of the array and set max height
    for i in np.nditer(heights):
        if i > max:
            max = i
    #Return max height
    return max
#Test
N=22 # for 22 players
H= np.random.uniform(5.5, 8.0, size=(1,N))
print("random float array in [5.5, 8.0] \n", H,"\n")
print("Tallest player height = %.8f"%tallestHeight(H))

Output

random float array in [5.5, 8.0]
[[7.53450756 7.14316657 6.34246178 7.78411501 5.51282309 7.74859553
7.62140945 5.59460712 5.86448351 5.87944372 5.76947077 6.00740081
7.39301746 7.57616436 7.61333592 7.01673579 5.80868431 6.32778803
6.98718796 7.79752271 7.42343135 5.51697551]]

Tallest player height = 7.79752271

-------------------------------------------------------------------------------------------------------------------

Matlab

Screenshot

Program

function max=tallestHeight(H)
max=H(1);
for i=H
     if i>max
       max=i;
     end
end
end

Test:-

H= (8.0-5.5).*rand(1, 22, 'double')+5.5

fprintf("Tallest player height = %.8f",tallestHeight(H));


Related Solutions

Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
Write a MATLAB code for importing an image and then being able to find all the...
Write a MATLAB code for importing an image and then being able to find all the coordinates that would draw that image on a plot column by column and row by row with a continuous line.
Use Matlab to write the following 1. Write code to determine whether a year is a...
Use Matlab to write the following 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100, but not by 400, are not leap years. Years divisible by 4, but not by 100, are leap years. All other years are not leap years. For example, the years 1800,...
write a matlab code to find the following: initial position, initial velocity, and acceleration using the...
write a matlab code to find the following: initial position, initial velocity, and acceleration using the algorithm and information below time(seconds). height(m) velocity(m/s) 0. 0.2. 2.95 algorithm: 1. Enter data in to arrays. 2. Fit the height data to a 2nd order polynomial. 3. Evaluate the polynomial at enough points to get a smooth curve. 4. Find the velocity model by taking derivative of the height polynomial. 5. Evaluate the velocity polynomial at enough times to get a smooth curve
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures...
My projects is to write or find Matlab code for 4FSK(frequency shift keying) with simulation pictures and create the signal after that add noise to it and finally demodulate it .. Please help me to do this project.
Practice for Matlab. You can create own f(x). a. Write code to find and plot a...
Practice for Matlab. You can create own f(x). a. Write code to find and plot a root using the modified secant method b. Find the roots using the roots command - identify and plot root of interest c. Use polyder and roots to find and plot the minimum value d. use fminbnd to find and plot minimum value Thank you!
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT