How to solve a nested summation with recursive function?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Irvanda Kurniadi Virdaus
el 7 de Nov. de 2018
Editada: Irvanda Kurniadi Virdaus
el 7 de Nov. de 2018
Hi,
I have a question related to solving a nested summation equation with a recursive function.
Suppose I have an equation of:

So, I tried to solve this problem by using a for loop to solve the summation equation and using a recursive function to expand the order of nested summation.
test(3,0)
function [sum] = test(a,b)
sum = 0;
for i=1:a-b
if a-b == 1
sum = 1;
else
sum = sum + (a-b) * test(a,b+i);
end
end
end
From the code I got
ans = 9
I appreciate any help, thanks.
0 comentarios
Respuesta aceptada
Matt J
el 7 de Nov. de 2018
Editada: Matt J
el 7 de Nov. de 2018
I think your code is correct, and your calculation by hand is not.
1 comentario
Irvanda Kurniadi Virdaus
el 7 de Nov. de 2018
Editada: Irvanda Kurniadi Virdaus
el 7 de Nov. de 2018
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing 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!