Write a function in Matlab that takes as input s and a number x and outputs the
ID: 3846860 • Letter: W
Question
Write a function in Matlab that takes as input s and a number x and outputs the floating point number of x using s-digit rounding. You may use Matlab’s “round” command to help you. Use only basic programming.
(a) Write out or print out your function
(b) Choose 2 random vectors of length 10, using the “rand” command, and compute the result of the dot product using your function under 4-digit rounding and compute the exact Matlab result and compute the absolute error. Do the same thing 4 more times and turn in the results.
Explanation / Answer
function [m,s] = stat2(x) n = length(x); m = avg(x,n); s = sqrt(sum((x-m).^2/n)); end function m = avg(x,n) m = sum(x)/n; rand();n end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.