Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECE 204 Numerical methods

Project 5

You have the following task:

You have a device that given a particular input voltage v such that the output is a voltage that is the sum of periodic functions depending on the input voltage, f(v). Your employer requires you to determine as accurately as possible the range of the output without overestimating it: that is, the maximum output voltage minus minimum output voltage.

For example, the range off(v) = sin(v) on the input range ofvoltages 0 < v < 10 is 2.

The range off(v) = sin(v) + sin(2v + 1) on the input range of voltages 0 < v < 10 is 2 is approximately 3.356512126558125.

Your employer requires both a good answer and a minimal number of evaluations, as in reality, you will be sampling an actual device, where the values will be sampled from the device; however, you will author a function that simulates finding this maximum range:

double range( std::function< double(double) > f,

double a,

double b,

double max_freq );

The maximum frequency will give the maximum frequency of any sinusoid, so sin( 2v ) has a frequency of 1, and sin( 4v ) has a frequency of 2, and the period is the reciprocal ofthe frequency. Please remember that the maximum or minimum may be at an end point, so you should include these in your consideration.

Grading: Half of the grades will come from documentation, as submitted on Crowdmark. The other half will come from a comparison of your program with that of your peers.

10 marks will come from your documentation on Crowdmark.

10 marks will be graded as follows:

1.   The student in class that has the fewest function evaluations nmin off will be awarded 10 marks, and

                     n  

function evaluations. Thus, 41.4% more function evaluations will result in a decrease in your grade of 1 mark, and twice as many function evaluations will result in a loss of 2 marks. 566% more function evaluations will result in a grade of 5, and 3200% more function evaluations or more will result in a grade of 0.

2.    10 marks will be graded as follows: returning a number greater than the range will automatically result in a grade of 0, so do not calculate a range using anything other than explicit function

                                   r      r 

You will submit your documentation on Crowdmark, and you will submit your code on Learn as follows:

1.   You will have a file range.hpp which contains a function declaration and relevant include files (such as <functional>).

2.   You can either implement your function in the  .hpp file, or you can include one or more  .cpp files where you define your functions and any helper functions.

3.   Your files will be tarred and gzipped and submitted. Submitting a  .zip file will automatically result in a 0 in the project (no exceptions), including a 0 in any submitted documentation. Renaming a .zip file .tar.gz does not work, either, and will result in a 0. The name of the submitted file uwuserid_p5.tar.gz where uwuserid is your up-to-eight-character  uWaterloo User ID, so for example, this instructor would use dwharder_p5.tar.gz .

4.   The code will be executed on eceubuntu.uwaterloo.ca.

The instructor will provide a file with a void main() function. Your submission must not include any file that has a main function declared or defined.

You may use any function in the standard library and you may author as many helper functions as you wish.

If you are interested in trying to determine how often a function is called, consider the following:

double f( double x ) {

// Static variables are shared by all calls to a function    //  - they cannot be accessed from outside the function call static unsigned long count{ 0 };

if ( x == INFINITY ) {

return count;

} else {

++count;

return std::sin( x );

}

}