Implement the following function in MATLAB and make sure to provide proper and d
ID: 3806030 • Letter: I
Question
Implement the following function in MATLAB and make sure to provide proper and detailed comments that can be followed easily: This function called polyeval takes as parameters a polynomial representation as an array and a number to evaluate. For example, if the first parameter passed is [-4 0 13 6], it represents -4 + 13x^2 + 6x^3. For the second parameter, if 3 is passed, then a for loop can be used to calculate the value as follows: -4 * 3^0 + 0 * 3^1 + 13 * 3^2 + 6 * 3^3. The function returns the result of the evaluation.Explanation / Answer
% declare function
function res = polyeval(arr, x)
%set the result value to 0
res = 0
%iterate through each element in the array
for indx = 1:numel(arr)
%since the matlab indices start from one we have to put the value x to the power of index-1.
res = res + (arr[indx]*(x.^(index-1)))
end