Question: Write a MATLAB function that evaluates a polynomial function f(x) = ax+aN_x1 + ...ax + ao of order N for a scalar value x.
Write a MATLAB function that evaluates a polynomial function f(x) = ax+aN_x1 + ...ax + ao of order N for a scalar value x. The function should take a 1 by N+1 array (index 1 to N+1 to be N+1 terms) containing the polynomial coefficients and a scalar value x, and should return the polynomial function value f(x). The coefficient ay for the highest power of x is the first element of the coefficient array and the coefficient an is the last element of the coefficient array. A sample polynomial function f(x) = 3.5x + 1.5 and value x = 1.0 would look like: a = [3.5, 1.5]; x = 1.0; then implement your function Use a loop (while or for) to calculate the result. Think about how will you implement it using element-by-element operation yourself, do not implement it here. Do not use sum in calculating your result. The input of your function is a and x, that will define the polynomial function. The output of your function is y. function y = myFunction(a, x) Test the function for the following cases on your own MATLAB installation. f(x) = 3.5x+1.5 for x = 0 f(x) = 3.5x + 1.5 for x = 3 f(x)=x-2.5x + 0.7 for x = 0 f(x)=x-2.5x+0.7 for x = -2 " B Your function should work for any possible test cases passed through a and x, not just the above ones.
Step by Step Solution
3.36 Rating (149 Votes )
There are 3 Steps involved in it
function y myFunctiona x N lengtha 1 y 0 for i 1N1 y ... View full answer
Get step-by-step solutions from verified subject matter experts
