Question: probelm #1 [Print and submit] Please include an example function call and the resulting output values from your function in your comments. Write a function

probelm #1

[Print and submit] Please include an example function call and the resulting output values from your function in your comments. Write a function that has one input, array1, and two outputs output, medianValue and meanValue. These outputs are as follows:

1-- medianValue is the median of the numbers in your array. The median is the number in the array that has exactly the same number of values that are greater than or equal to it as it has values that are less than or equal to it. In an array with an odd number of indices, this is a value from the array itself. In an array with an even number of indices, this is the average of the two middle values in the array. For example, for the array [5 8 9 1 0 2 3 1 9], the median is [0 1 1 2 3 5 8 9 9] 3. For the array [10 2 11 3 12 4], the median is [2 3 4 10 11 12] (4+10)/2 = 7. Note that the numbers before and after the median can be the same as the median. The median of [1 2 2 2 2 2 2 2 2 2 3] is [1 2 2 2 2 2 2 2 2 2 3]

2. - --meanValue is the average of all of the numbers in the array. You should use a loop or multiple loops to find both of these, and you should NOT call either of the following built-in MATLAB functions: - mean - median - sum Other functions, like sort and length are allowed, and may be useful to you.

probelm #2

[Print out and submit] Please include an example function call and the resulting output values from your function in your comments. Loops are very useful for doing the same calculation over and over, very quickly. Lets assume that we have a large fleet of electric cars, and we are trying to figure out how far all of them can drive. Write program that takes one input, an array of battery percentages. It should return two outputs:

- A sorted array of how far each car can drive, in descending order.

- The corresponding array of indices that maps the sorted array of distances to the original battery levels, so we can still keep track of which car is which. This function should NOT make any actual calculations mapping battery power to distance. Instead, it should call your function from Recitation 3 Problem 2 to make those calculations. In other words, functions that contain conditional statements will lose points! Calling other built in MATLAB functions is also acceptable, and functions, like sort and length are allowed, and may be useful to you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!