How can I sum a number of terms as a polynomial?

조회 수: 1 (최근 30일)
Gabriel
Gabriel 2023년 8월 20일
편집: Walter Roberson 2023년 8월 20일
My code performs the individual calculation of each term of my polynomial, which is not exactly a polynomial, however, I need it to output the total sum of all these terms, I have no idea what to do. In my code x is the input, I have been using 1 to facilitate the calculations, and n is the number of terms that must be added to my final result:
while i<=n
ex = (x^i);
fat = factorial(i-1);
soma = ex / fat;
i=i+1;

채택된 답변

dpb
dpb 2023년 8월 20일
"Dead ahead" straightforward would be
S=0;
for i=1:n
S=S+x^i/factorial(i-1);
end
Alternatively, vectorized could be
i=1:n;
S=sum(x.^i./factorial(i-1));
  댓글 수: 14
Bruno Luong
Bruno Luong 2023년 8월 20일
편집: Bruno Luong 2023년 8월 20일
(hard to find or easy to find it, depending on your understanding of Taylor)
Torsten
Torsten 2023년 8월 20일
Yes, but you have to know that it's f(x) = x*exp(x) that you are approximating. Usually the explicit form of f is unknown.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by