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

답변 (2개)

Image Analyst
Image Analyst 2016년 9월 5일

1 개 추천

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

댓글 수: 2

ahmed lamak
ahmed lamak 2016년 9월 5일
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

댓글을 달려면 로그인하십시오.

Stephen23
Stephen23 2016년 9월 5일
편집: Stephen23 2016년 9월 5일

0 개 추천

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

댓글 수: 2

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Polynomials에 대해 자세히 알아보기

질문:

2016년 9월 5일

댓글:

2016년 9월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by