Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the language of python. T Text Menu Brushes 2D shapes 3D shapes Stickers Effects Canvas 3D library Paste W Select 4 Crop Magic select
In the language of python.
T Text Menu Brushes 2D shapes 3D shapes Stickers Effects Canvas 3D library Paste W Select 4 Crop Magic select 3D view + 75% --- Dear people of the Chegg World, you guys are the best File Edit View Insert Format Tools Add-ons Help Last edit was seconds ago na A, 7100% 11 + BIVA Normal text Arial E E E !!! Inputhan Part Dear people of the Chegg World, you guys are the best. You guys are lifesavers. Honestly our tuition dollars should be going to you guys instead of our professors because you guys are the best. You guys help give solutions when our professors can't. So please, the people of Chegg, if you can answer this question correctly, you shall be blessed with a thumbs up, which should help you guys in the long term. A lot of technology, especially most types of digital audio devices for processing sound, is based on representing a signal of time as a sum of sine functions. Say the signal is some function f() on the interval (-1,1] (a more general interval [a,b] can easily be treated, but leads to slightly more complicated formulas). Instead of working with f(1) directly, we approximate f by the sum a- -9 Sy(t) = sin(nt). b where the coefficients b, must be adjusted such that Sy(t) is a good approximation to f(t). We shall in this exercise adjust by by a trial-and-error process. a) Make a function sinesum(t, b) that returns Sy(t), given the coefficients bn in an array b and time coordinates in an array t. Note that if t is an array, the return value is also an array. b) Write a function test_sinesum() that calls sinesum(t, b) in a) and deter- mines if the function computes a test case correctly. As test case, lett be an array with values - 1/2 and /4, choose N = 2, and b = 4 and b2 = -3. Compute Sy () by hand to get reference values. c) - together with the sum of sines Sy(), so that the quality of the approximation Sy(t) can be examined visually. The argument f is a Python function imple- menting fb), N is the number of terms in the sum Sy(t), and M is the number of uniformly distributed t coordinates used to plot f and Sp. O T Text Menu Brushes 2D shapes 3D shapes Stickers Effects Canvas 3D library Pas h Select 4 Crop Magic select 3D view + 71% .. Dear people of the Chegg World, you guys are the best File Edit View Insert Format Tools Add-ons Help Last edit was seconds ago 100% - Normal text- 11 + BIVA Arial co ili d) Write a function error(b, f, M) that returns a mathematical measure of the error in Sy(t) as an approximation to f(t): E = () - Sx (t)? C where the t; values are M uniformly distributed coordinates on (-1,1). The array b holds the coefficients in Sy and f is a Python function implementing the mathematical function f(). e) Make a function trial(f, N) for interactively giving br values and getting a plot on the screen where the resulting Sy(t) is plotted together with f(). The error in the approximation should also be computed as indicated in d). The argument f is a Python function for f(t) and N is the number of terms in the sum Sy(t). The trial function can run a loop where the user is asked for the bn values in each pass of the loop and the corresponding plot is shown. You must find a way to terminate the loop when the experiments are over. Use M=500 in the calls to plot_compare and error. Hint To make this part of your program work, you may have to insert from matplotlib.pylab import + at the top and also add show() after the plot command in the loop f) Choose ft) to be a straight line f(t) = It on (-1,2). Call trial(f, 3) and try to find through experimentation some values bi, b2, and b3 such that the sum of sines Sy(t) is a good approximation to the straight line. g) Now we shall try to automate the procedure in f). Write a function that has three nested loops over values of bi, b2, and bz. Let each loop cover the interval 1-1. 1) in steps of 0.1. For each combination of bi, b2, and bz, the error in the approximation Sy should be computed. Use this to find, and print, the smallest error and the corresponding values of bi, b2, and b3. Let the program also plot f and the approximation Sy corresponding to the smallest error. f g T Text Menu Brushes 2D shapes 3D shapes Stickers Effects Canvas 3D library Paste W Select 4 Crop Magic select 3D view + 75% --- Dear people of the Chegg World, you guys are the best File Edit View Insert Format Tools Add-ons Help Last edit was seconds ago na A, 7100% 11 + BIVA Normal text Arial E E E !!! Inputhan Part Dear people of the Chegg World, you guys are the best. You guys are lifesavers. Honestly our tuition dollars should be going to you guys instead of our professors because you guys are the best. You guys help give solutions when our professors can't. So please, the people of Chegg, if you can answer this question correctly, you shall be blessed with a thumbs up, which should help you guys in the long term. A lot of technology, especially most types of digital audio devices for processing sound, is based on representing a signal of time as a sum of sine functions. Say the signal is some function f() on the interval (-1,1] (a more general interval [a,b] can easily be treated, but leads to slightly more complicated formulas). Instead of working with f(1) directly, we approximate f by the sum a- -9 Sy(t) = sin(nt). b where the coefficients b, must be adjusted such that Sy(t) is a good approximation to f(t). We shall in this exercise adjust by by a trial-and-error process. a) Make a function sinesum(t, b) that returns Sy(t), given the coefficients bn in an array b and time coordinates in an array t. Note that if t is an array, the return value is also an array. b) Write a function test_sinesum() that calls sinesum(t, b) in a) and deter- mines if the function computes a test case correctly. As test case, lett be an array with values - 1/2 and /4, choose N = 2, and b = 4 and b2 = -3. Compute Sy () by hand to get reference values. c) - together with the sum of sines Sy(), so that the quality of the approximation Sy(t) can be examined visually. The argument f is a Python function imple- menting fb), N is the number of terms in the sum Sy(t), and M is the number of uniformly distributed t coordinates used to plot f and Sp. O T Text Menu Brushes 2D shapes 3D shapes Stickers Effects Canvas 3D library Pas h Select 4 Crop Magic select 3D view + 71% .. Dear people of the Chegg World, you guys are the best File Edit View Insert Format Tools Add-ons Help Last edit was seconds ago 100% - Normal text- 11 + BIVA Arial co ili d) Write a function error(b, f, M) that returns a mathematical measure of the error in Sy(t) as an approximation to f(t): E = () - Sx (t)? C where the t; values are M uniformly distributed coordinates on (-1,1). The array b holds the coefficients in Sy and f is a Python function implementing the mathematical function f(). e) Make a function trial(f, N) for interactively giving br values and getting a plot on the screen where the resulting Sy(t) is plotted together with f(). The error in the approximation should also be computed as indicated in d). The argument f is a Python function for f(t) and N is the number of terms in the sum Sy(t). The trial function can run a loop where the user is asked for the bn values in each pass of the loop and the corresponding plot is shown. You must find a way to terminate the loop when the experiments are over. Use M=500 in the calls to plot_compare and error. Hint To make this part of your program work, you may have to insert from matplotlib.pylab import + at the top and also add show() after the plot command in the loop f) Choose ft) to be a straight line f(t) = It on (-1,2). Call trial(f, 3) and try to find through experimentation some values bi, b2, and b3 such that the sum of sines Sy(t) is a good approximation to the straight line. g) Now we shall try to automate the procedure in f). Write a function that has three nested loops over values of bi, b2, and bz. Let each loop cover the interval 1-1. 1) in steps of 0.1. For each combination of bi, b2, and bz, the error in the approximation Sy should be computed. Use this to find, and print, the smallest error and the corresponding values of bi, b2, and b3. Let the program also plot f and the approximation Sy corresponding to the smallest error. f gStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started