Trying to make symsum work.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jacob Oleshchuk
el 27 de Nov. de 2018
Comentada: Walter Roberson
el 27 de Nov. de 2018
I am having problems getting symsum to calculate the following sumation within this equation:

I am using the following code to get pi:
function piram
%approximates and prints pi with Ramanujan's formula
%called as piram or piram()
%doesn't return a value, but a print
k=sym('k');
sumpart=symsum((factorial(4*k)*(1103+26390*k))/(((factorial(k))^4)*(396^(4*k))),k,0,inf);
inverted=sumpart*((2*sqrt(2))/9801);
approxpi=1/inverted;
fprintf('Using Ramanujan''s formula, a good approximation is %.6f\n',approxpi)
end
Can anyone help with this?
Respuesta aceptada
Steven Lord
el 27 de Nov. de 2018
If the only factorial function that appears when you execute:
which -all factorial
is the one included in MATLAB, you probably don't have Symbolic Math Toolbox installed. Check the output of the ver function to test whether you have it installed. If you don't have Symbolic Math Toolbox installed, I would have expected the sym or syms calls to error before you even reached the line where you called symsum, but it's possible you've written your own functions named sym or syms that are being used instead of the versions from Symbolic Math Toolbox.
If what you posted in response to madhan ravi's question was the output of which factorial (without the -all flag) try it with the -all flag and show us what that returns.
4 comentarios
Walter Roberson
el 27 de Nov. de 2018
As you are a student you might be able to test your code on MATLAB Online .
Más respuestas (1)
madhan ravi
el 27 de Nov. de 2018
function piram
syms k
sumpart=symsum((factorial(4*k)*(1103+26390*k))/(((factorial(k))^4)*(396^(4*k))),k,0,inf);
inverted=sumpart*((2*sqrt(2))/9801);
approxpi=1/inverted;
fprintf('Using Ramanujan''s formula, a good approximation is %.6f\n',approxpi)
end
15 comentarios
Walter Roberson
el 27 de Nov. de 2018
What shows up for
which factorial(k)
Question: is it possible that you have Maple installed but not the MATLAB Symbolic Toolbox ?
Ver también
Categorías
Más información sobre Assumptions 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!
