How do I change the sign without altering the other and how can I do the factorial denominator? 1-1/3!+1/5!-1/7!+... and perform the sum?

조회 수: 1 (최근 30일)
disp('serie 4: 1-1/3!+1/5!-1/7!+...' )
n=input('Enter a number: ');
sum=0;
for j=1:2:n
sum = sum + 1/j;
end
disp('the sum is: ')
disp(sum)
I don't know how to do that series please someone help me if you can.
  댓글 수: 4
the cyclist
the cyclist 2022년 5월 24일
Try googling matlab factorial.
:-)
Also, if you post your code, folks can make more specific suggestions. (You can use the paperclip icon in the INSERT section of the toolbar.)

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

채택된 답변

David Hill
David Hill 2022년 5월 24일
편집: David Hill 2022년 5월 24일
disp('serie 4: 1-1/3!+1/5!-1/7!+...' )
n=input('Enter a number: ');
Sum=0;
for j=1:n
Sum = Sum + (-1)^(j+1)/factorial(2*j-1);
end
disp('the sum is: ')
disp(Sum)
alternatively, no for-loop needed.
Sum=sum((-1).^(0:n-1)./factorial(1:2:2*n));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by