Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB function that computes the Absolute Relative Error(ARE) between t

ID: 3788378 • Letter: W

Question

Write a MATLAB function that computes the Absolute Relative Error(ARE) between two functions.  The functions, for which the error is being computed, are to be passed into the function you are creating.  A template of for the function call is included here.

function [Error,x,y1,y2] = AbsRelativeError( NumberOfPoints, ...StartingValue, StoppingValue, ...Function1, Function2 )

Then use this function to compute the error in the approximation of sin(x)=x for|x| < pi/4.  Your program should compute sin(x) and the ARE of  sin(x) .vs. x, for about 500 points between -pi/4 to pi/4.

Explanation / Answer

% matlab code

function [Error,x,y1,y2] = AbsRelativeError( NumberOfPoints, StartingValue, StoppingValue, Function1, Function2 )
% Create a vector of NumberOfPoints evenly spaced points in the interval [StartingValue,StoppingValue].
x = linspace( StartingValue, StoppingValue,NumberOfPoints);
y1 = Function1(x);
y2 = Function2(x);
Error = abs(y1-y2)/y2;
end

% values to function
[Error,x,y1,y2] = AbsRelativeError( 500, -1*(pi/4), (pi/4), @(x)x, @(x)sin(x) );
disp("Absolute Relative Error: ");
disp(Error);

%{
Absolute Relative Error::   
1.5988e-17
%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote