Functions and For Loops For Polynomials
Afficher commentaires plus anciens
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?
2 commentaires
James Tursa
le 31 Mar 2020
What have you done so far? What specific problems are you having with your code?
Alex Baham
le 31 Mar 2020
Réponse acceptée
Plus de réponses (1)
David Hill
le 31 Mar 2020
Too bad you can't use polyval(). This might get you started.
function e=evalPoly(p,a)
x=1;
e=0;
for k=1:length(p)
e=e+p(k)*x;
x=x*a;
end
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!