simple coding, how to write (x-1)...(x-n)

回答(2 个)

Try this:
result = 1
for k = 1 : n
result = result * (x - k);
end

2 个评论

i gave a simple example as the zeros being 1 : n, if they were rather complicated values and denoted as say z(1),z(2),...,z(n) this method wont work?
You can do this:
result = 1
for k = 1 : length(z)
result = result * (x - z(k));
end

请先登录,再进行评论。

The simplest solution, without any loops:
prod(x-z)

2 个评论

I do not understand why you are raising to the z'th power ??
@Walter Roberson: experimenting around, and not paying enough attention to the copy-and-paste :(

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by