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

ID: 3789249 • 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) % [Error, x, y1, y2] = AbsRelativeError(NumberOfPoints, StartingValue, ... StoppingValue, Function1, Function2); % Computes the absolute relative error, between two functions. % The error is computed at N incremental steps between Start and Stop. % Inputs: NumberOfPoints - Number of points to be compared. % StartingValue - Starting point for the comparison % StoppingValue - Stopping point for the comparison % Function1 - a function (i.e. @sin) for comparison. %Function2 - 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 % y1 - values of Function1 at x (Function1(x)) % y2 - values of Function2 at x (Function2(x))%

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);
end

% values to function
[Error,x,y1,y2] = AbsRelativeError( 500, -1*(pi/4), (pi/4), @(x)x, @(x)sin(x) );
disp("Error: ");
disp(Error);
sum = sum(Error);
avgApprox = sum/length(Error);
fprintf("Average Absolute Relative error: %f ",avgApprox);
% output: Average Absolute Relative error: 0.019893


%{
Error:
Columns 1 through 7
0.0783 0.0774 0.0765 0.0756 0.0747 0.0738 0.0729
Columns 8 through 14
0.0720 0.0711 0.0703 0.0694 0.0686 0.0677 0.0669
Columns 15 through 21
0.0661 0.0652 0.0644 0.0636 0.0628 0.0620 0.0612
Columns 22 through 28
0.0604 0.0597 0.0589 0.0581 0.0574 0.0566 0.0559
Columns 29 through 35
0.0551 0.0544 0.0537 0.0530 0.0523 0.0515 0.0508
Columns 36 through 42
0.0502 0.0495 0.0488 0.0481 0.0474 0.0468 0.0461
Columns 43 through 49
0.0455 0.0448 0.0442 0.0435 0.0429 0.0423 0.0417
Columns 50 through 56
0.0411 0.0405 0.0399 0.0393 0.0387 0.0381 0.0375
Columns 57 through 63
0.0370 0.0364 0.0359 0.0353 0.0348 0.0342 0.0337
Columns 64 through 70
0.0331 0.0326 0.0321 0.0316 0.0311 0.0306 0.0301
Columns 71 through 77
0.0296 0.0291 0.0286 0.0281 0.0277 0.0272 0.0268
Columns 78 through 84
0.0263 0.0258 0.0254 0.0250 0.0245 0.0241 0.0237
Columns 85 through 91
0.0232 0.0228 0.0224 0.0220 0.0216 0.0212 0.0208
Columns 92 through 98
0.0204 0.0201 0.0197 0.0193 0.0189 0.0186 0.0182
Columns 99 through 105
0.0179 0.0175 0.0172 0.0168 0.0165 0.0162 0.0158
Columns 106 through 112
0.0155 0.0152 0.0149 0.0146 0.0143 0.0140 0.0137
Columns 113 through 119
0.0134 0.0131 0.0128 0.0125 0.0123 0.0120 0.0117
Columns 120 through 126
0.0115 0.0112 0.0109 0.0107 0.0104 0.0102 0.0100
Columns 127 through 133
0.0097 0.0095 0.0093 0.0090 0.0088 0.0086 0.0084
Columns 134 through 140
0.0082 0.0080 0.0078 0.0076 0.0074 0.0072 0.0070
Columns 141 through 147
0.0068 0.0066 0.0064 0.0062 0.0061 0.0059 0.0057
Columns 148 through 154
0.0056 0.0054 0.0053 0.0051 0.0049 0.0048 0.0047
Columns 155 through 161
0.0045 0.0044 0.0042 0.0041 0.0040 0.0038 0.0037
Columns 162 through 168
0.0036 0.0035 0.0034 0.0032 0.0031 0.0030 0.0029
Columns 169 through 175
0.0028 0.0027 0.0026 0.0025 0.0024 0.0023 0.0022
Columns 176 through 182
0.0021 0.0021 0.0020 0.0019 0.0018 0.0017 0.0017
Columns 183 through 189
0.0016 0.0015 0.0015 0.0014 0.0013 0.0013 0.0012
Columns 190 through 196
0.0011 0.0011 0.0010 0.0010 0.0009 0.0009 0.0008
Columns 197 through 203
0.0008 0.0008 0.0007 0.0007 0.0006 0.0006 0.0006
Columns 204 through 210
0.0005 0.0005 0.0005 0.0004 0.0004 0.0004 0.0003
Columns 211 through 217
0.0003 0.0003 0.0003 0.0003 0.0002 0.0002 0.0002
Columns 218 through 224
0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001
Columns 225 through 231
0.0001 0.0001 0.0001 0.0001 0.0001 0.0000 0.0000
Columns 232 through 238
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 239 through 245
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 246 through 252
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 253 through 259
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 260 through 266
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 267 through 273
0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001
Columns 274 through 280
0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001
Columns 281 through 287
0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003
Columns 288 through 294
0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004
Columns 295 through 301
0.0005 0.0005 0.0005 0.0006 0.0006 0.0006 0.0007
Columns 302 through 308
0.0007 0.0008 0.0008 0.0008 0.0009 0.0009 0.0010
Columns 309 through 315
0.0010 0.0011 0.0011 0.0012 0.0013 0.0013 0.0014
Columns 316 through 322
0.0015 0.0015 0.0016 0.0017 0.0017 0.0018 0.0019
Columns 323 through 329
0.0020 0.0021 0.0021 0.0022 0.0023 0.0024 0.0025
Columns 330 through 336
0.0026 0.0027 0.0028 0.0029 0.0030 0.0031 0.0032
Columns 337 through 343
0.0034 0.0035 0.0036 0.0037 0.0038 0.0040 0.0041
Columns 344 through 350
0.0042 0.0044 0.0045 0.0047 0.0048 0.0049 0.0051
Columns 351 through 357
0.0053 0.0054 0.0056 0.0057 0.0059 0.0061 0.0062
Columns 358 through 364
0.0064 0.0066 0.0068 0.0070 0.0072 0.0074 0.0076
Columns 365 through 371
0.0078 0.0080 0.0082 0.0084 0.0086 0.0088 0.0090
Columns 372 through 378
0.0093 0.0095 0.0097 0.0100 0.0102 0.0104 0.0107
Columns 379 through 385
0.0109 0.0112 0.0115 0.0117 0.0120 0.0123 0.0125
Columns 386 through 392
0.0128 0.0131 0.0134 0.0137 0.0140 0.0143 0.0146
Columns 393 through 399
0.0149 0.0152 0.0155 0.0158 0.0162 0.0165 0.0168
Columns 400 through 406
0.0172 0.0175 0.0179 0.0182 0.0186 0.0189 0.0193
Columns 407 through 413
0.0197 0.0201 0.0204 0.0208 0.0212 0.0216 0.0220
Columns 414 through 420
0.0224 0.0228 0.0232 0.0237 0.0241 0.0245 0.0250
Columns 421 through 427
0.0254 0.0258 0.0263 0.0268 0.0272 0.0277 0.0281
Columns 428 through 434
0.0286 0.0291 0.0296 0.0301 0.0306 0.0311 0.0316
Columns 435 through 441
0.0321 0.0326 0.0331 0.0337 0.0342 0.0348 0.0353
Columns 442 through 448
0.0359 0.0364 0.0370 0.0375 0.0381 0.0387 0.0393
Columns 449 through 455
0.0399 0.0405 0.0411 0.0417 0.0423 0.0429 0.0435
Columns 456 through 462
0.0442 0.0448 0.0455 0.0461 0.0468 0.0474 0.0481
Columns 463 through 469
0.0488 0.0495 0.0502 0.0508 0.0515 0.0523 0.0530
Columns 470 through 476
0.0537 0.0544 0.0551 0.0559 0.0566 0.0574 0.0581
Columns 477 through 483
0.0589 0.0597 0.0604 0.0612 0.0620 0.0628 0.0636
Columns 484 through 490
0.0644 0.0652 0.0661 0.0669 0.0677 0.0686 0.0694
Columns 491 through 497
0.0703 0.0711 0.0720 0.0729 0.0738 0.0747 0.0756
Columns 498 through 500
0.0765 0.0774 0.0783
%}

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