Home / Expert Answers / Computer Science / use-matlab-someone-gave-you-a-black-box-function-f-x-y-fun-mathrm-x-mathrm-x-pa397

(Solved): Use MATLAB. Someone gave you a black-box function \( f(x) \) [y=fun_ \( \mathrm{x}(\mathrm{x}) \) ...



Someone gave you a black-box function \( f(x) \) [y=fun_ \( \mathrm{x}(\mathrm{x}) \) provided], but is unwilling to share wi

Use MATLAB.

Someone gave you a black-box function \( f(x) \) [y=fun_ \( \mathrm{x}(\mathrm{x}) \) provided], but is unwilling to share with you its analytic expression. Unfortunately, you suspect that some random noise was introduced to the output of the function. Step 1: Plot the function - Evaluate the value of the function for \( x \in[-1,1] \) (use linspace \( (-1,1,100) \) ) and plot it in subplot \( (3,1,1) \). Step 2: Centered difference derivative - Calculate the first derivative of the function for vector \( x \) using the centered difference scheme. Save the values of this derivative in vector \( y p \) and corresponding \( x \) values in \( x c \). - Plot the centered difference derivative \( (y p v s x c) \) in subplot \( (3,1,2) \). Step 3: Complex-step derivative - Now that you are almost certain some noise has been added to the output of the black-box function, use the complex-step scheme to estimate the derivative of the function (see the lecture slides). - Save the complex-step estimate of the derivative for vector \( x \) as ypc. - Plot the complex-step derivative in subplot \( (3,1,2) \) on top of the previous (centered-difference) estimate. Step 4: Integral using trapezoidal rule - Calculate \( f_{a}(x)=f(-1)+\int_{-1}^{x} f^{\prime}(\tilde{x}) d \tilde{x} \) for \( x \in[-1,1] \) and store the integral as vector fa, where \( f(-1) \) is the function evaluation at \( x=-1 \) and \( f^{\prime}(\tilde{x}) \) is your complex-step estimate of the black-box function derivative. - Plot fa vs. \( x \) in subplot \( (3,1,1) \), on top of the original function plot. Step 5: noise histogram - Plot the histogram of the difference between \( f a \) and \( f \) in subplot \( (3,1,3) \) to get a sense of the underlying distribution of the noise added to the black-box function (Hint: you may want to increase the number of points when generating \( x \in[-1,1] \) to get a better sense of the distribution).


We have an Answer from Expert

View Expert Answer

Expert Answer


The matlab code for given problem statement is as follows: % Step 1: Plot the function x = linspace(-1,1,100); y = fun_x(x); subplot(3,1,1); plot(x,y)
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe