Functions and For Loops For Polynomials
显示 更早的评论
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 个评论
James Tursa
2020-3-31
What have you done so far? What specific problems are you having with your code?
Alex Baham
2020-3-31
采纳的回答
更多回答(1 个)
David Hill
2020-3-31
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
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!