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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.