Nth term of a Leibniz Series
42 ビュー (過去 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 で Outputs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!