Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A: Geometric, RMS and Harmonic Mean Part 1 of this lab will be implementing various mathematical calculations as functions. You are not allowed to

Part A: Geometric, RMS and Harmonic Mean

Part 1 of this lab will be implementing various mathematical calculations as functions. You are not allowed to use the geomean(), rms(), harmmean(), prod() or sum() functions. In other words, solve the problem in an elementary way using for-loops.

To start, download the Lab9 folder from Bblearn and move it to your cs122 directory. Also, be sure to cd into the Lab9 folder and add it to the path.

Open up the geometric_mean.m file in your Lab9 folder. For this function, you will be implementing the geometric mean of a set of numbers, which is defined as:

First, note that parameter being passed into the function (data). This data variable is a one dimensional vector of numbers, which correlates to the x1,x2,,xn in the above equation. This is where you will be using a for-loop, as you will need to loop through every element in the vector and multiply it with the product of the previous elements. Be sure that your return value (the geometric mean calculated using the equation above) is stored in the variable g_mean.

Once you have completed the geometric_mean function, open the root_mean_square.m file. In this function. You will be implementing the root-mean-square (rms), which is defined as:

The same concepts apply here. Data is a vector of elements, N is the number of elements in data, and the return value for the root_mean_square function should be stored in r_m_s.

When you have completed the root_mean_square function, open the harmonic_mean function. Implement the harmonic mean function, which is defined as:

Once again, data is your vector of elements, N is the number of elements in data, and the return value should be stored in the variable h_mean.

Now, it is time to use all of these functions in a single script. Open the Lab9a.m file. Read the comments carefully, as they will help you implement the script. The algorithm goes like this:

Load the data from data file: lab9_grades.txt. This file can be found in your Lab9 folder. Store it in a variable named data.

Call your geometric_mean function. Pass it the loaded data from step 1, and store it in a variable named g_mean. To do this, paste the following code in:

g_mean = geometric_mean(data);

Call our root_mean_square function. Pass it the loaded data from step 1, and store it in a variable named r_m_s. Refer to step 2 for how to call a function.

Call your harmonic_mean function. Pass it the loaded data from step1, and store it in a variable named h_mean.

Now you are going to print your g_mean, r_m_s and h_mean values. The format should look something like Geometric mean: and so on.

Check your work using the geomean(), rms() and harmmean functions. If the values dont match, take another look at the functions that you have implemented.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

18b5c3d-7 / 24b-6c3d-2 Simplify.

Answered: 1 week ago