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

2 Absolute and relative errors In this part of project, you will implement absol

ID: 3881359 • Letter: 2

Question

2 Absolute and relative errors In this part of project, you will implement absolute and relative errors formulus in MATLAB code. In the file errors.m, you will find the outline of a MATLAB function. Modify it to return absolute and relative errors if the true and approximate values of a quantity are given. Caution: When you write this code, be carefule about yr and yA- they could be values or vectors. Use element-by-element operations when necessary. When you are finished, run project2.m(assuming you are in the correct directory, type project2" at the command window of MATLAB). project2.m will use your function to cal- culate the absolute and relative errors using third Taylor polynomial at x = 0 to approximate y = e*. You should see output similar to the following:

Explanation / Answer

Matlab code :

function [abs_err, rel_err] = errors(yt, ya)

% yt is the measured value

% ya is the actual value

abs_err = yt - ya; % absolute error

rel_err = abs_err ./ ya; % relative error

end

Code Explanation :

We know,

absolute error = measured value - actual value

relative error = (measured value - actual value) / actual value

= absolute error / actual value

These formulas are used for calculating absolute error and relative error in the above function.

Sample Output :

[absolute, relative] = errors(6,2)

absolute =

4

relative =

2

Output explanation :

Absolute error = 6 - 2

= 4

Relative error = (6 -2) / 2

= 2

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