Write a MATLAB function that computes the Absolute Relative
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 for the function call is included here.
function [Error,x,y1,y2] = AbsRelativeError( NumberOfPoints, ...StartingValue, StoppingValue, ...Function1, Function2 )
Solution
function res=func1(x)
res=2.0*x
end
function res=func2(x)
res=2.01*x
end
function [Error,x,y1,y2] = AbsRelativeError(NumberOfPoints,StartingValue,StoppingValue,Function1,Function2)
curr=StartingValue
i=1
inc=(StoppingValue-StartingValue)/NumberOfPoints
Error=0.0
while(curr<=StoppingValue)
Error=Error+abs(Function1(curr)-Function2(curr))
curr=curr+inc
x=curr
y1=Function1(curr)
y2=Function2(curr)
end
end
AbsRelativeError(10,0,10,@func1,@func2)
Explanation :
Firstly I defined two functions on my own which return almost same results with minute differences to simulate the error rate between two functions
then we define our \"AbsRelativeError\" function where we find the increment value by dividing the gap between starting and stopping value with no of points given.
using a while loop we call the functions to calculate the relative error and also sum it for all possible values of \"X\" as shown in code
While calling the function \"AbsRelativeError\" we use function handles to send the function names as arguments to a function.
