Nth term of a Leibniz Series
조회 수: 38 (최근 30일)
이전 댓글 표시
I'm trying to create a function that will take a signle input (N) and output the Nth term in the Leibniz Series but for some reason my code keeps failing to pass these test: First term check, Check random variable.
Here is my function and how i am calling it.
test = LeibnizTerm(7)
function y = LeibnizTerm(N)
y = (-1)^N/(2*N+1);
end
댓글 수: 0
채택된 답변
Voss
2022년 2월 25일
It depends on if the first term should correspond to input N == 0 or input N == 1. If it's N == 0, I think it's ok how you have it.
LeibnizTerm(0)
LeibnizTerm(1)
LeibnizTerm(2)
If it should start with N == 1, then you have to make a couple of adjustments (see modified function LeibnizTerm1 below).
LeibnizTerm1(1)
LeibnizTerm1(2)
LeibnizTerm1(3)
function y = LeibnizTerm(N)
y = (-1)^N/(2*N+1);
end
function y = LeibnizTerm1(N)
y = (-1)^(N+1)/(2*N-1);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Hypothesis Tests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!