MATLAB: Functions and For Loops For Polynomials

for loopfunctionhomework

I need to write a function that takes two inputs, a vector that is the the coefficients of a polynomial starting with the lowest degree term and a scalar to evaluate it at, I'm supposed to use a for loop to evaluate it in the function. I also cannot use '^' this built in function. Any guidance?

Best Answer

Some guidance:
1) The sum=0 part needs to be moved outside the loop, prior to the loop starting. The way you have it the sum resets to 0 at each iteration.
2) Don't use "sum" as a variable name since that is an important existing MATLAB function name. Use something else, like "mysum" instead.
3) c is a vector of coefficients, so you should be indexing into c inside your loop. E.g., c(i)
4) The x needs to have an exponent applied to it based on the index i.
Make an attempt at these fixes and come back with any more problems you are having.
Related Question