Nth term of a Leibniz Series
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eric Brown
el 25 de Feb. de 2022
Respondida: Onimisi
el 22 de Feb. de 2023
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 comentarios
Respuesta aceptada
Voss
el 25 de Feb. de 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 comentarios
Ver también
Categorías
Más información sobre Outputs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!