I need help on Number 2 I am just showing question 1 incase

I need help on Number 2. I am just showing question 1 incase it helps.

1) (6 pts) 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, yl, y2] AbsRelative Error Numberof oints Starting Value Stopping Value Function Functi on [Error, x, yl, 2] AbsRelative Error Numberoff Points Star tingvalue Stopping Value Function Function 2 Computes the absolute relative error between two functions The error is computed at N incremental steps between Start and Stop Inputs NumberOf Points Number of points to be compared Starting Value Starting point for the comparison Stopping Value Stopping point for the comparison Function 1 a function (i.e. Csin for comparison Function 2 the second function in the comparison, also assumed to be the more accurate of the two functions outputs Error the ARE between the two functions x the values where the comparisons occurred yl values of Function 1 at x Function1 (x) 2 values of Function 2 at x Function (x)

Solution

% 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);
disp(\"Values of x for which relative error is less than 0.1 percent: \");
for i=1:length(x)
if abs(y1(i)-y2(i))/y2(i) < 0.001
fprintf(\"%f\ \",x);
end
end

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

I need help on Number 2. I am just showing question 1 incase it helps. 1) (6 pts) Write a MATLAB function that computes the Absolute Relative Error (ARE) betwee

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site