Nth term of a Leibniz Series
33 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 25 Fév 2022
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 commentaires
Voir également
Catégories
En savoir plus sur Outputs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!