I am having problems getting symsum to calculate the following sumation within this equation:
example.PNG
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?

댓글 수: 1

Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
Sidenote: My error occurs within the symsum

댓글을 달려면 로그인하십시오.

 채택된 답변

Steven Lord
Steven Lord 2018년 11월 27일

2 개 추천

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

Walter Roberson
Walter Roberson 2018년 11월 27일
People who have the MATLAB Connector for Maple installed but not the Symbolic Toolbox would have access to sym and syms but would be missing access to several symbolic functions.
Steven Lord
Steven Lord 2018년 11월 27일
Good to know.
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
I have tried to install the Symbolic Toolbox to no avail as the 'unzipper' (for lack of better term) has an error at the very end of execution. However, I believe that if this works for everyone else who DOES have that program extension, I should just be able to include a note with my project that informs my teacher that they require the Symbolic Toolbox to run the final function of my program (piram). Thanks much.
Walter Roberson
Walter Roberson 2018년 11월 27일
As you are a student you might be able to test your code on MATLAB Online .

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 27일

0 개 추천

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

Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
is...is my only issue with how i have the symbolic k set?
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
Wait, no this didn't fix the code, now it's saying this:
Error using factorial (line 20)
N must be an array of real non-negative integers.
Error in piram (line 7)
sumpart=symsum((factorial(4*k)*(1103+26390*k))/(((factorial(k))^4)*(396^(4*k))),k,0,inf);
madhan ravi
madhan ravi 2018년 11월 27일
편집: madhan ravi 2018년 11월 27일
clear all at the very beginning of the code , I got the answer in terms of pi as a decimal value , see attached picture
9F571451-5485-4C30-9215-FD2EA5581D41.jpeg
function piram
%approximates and prints pi with Ramanujan's formula
%called as piram or piram()
%doesn't return a value, but a print
clear all
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
This is my new code, it still results in:
Error using factorial (line 20)
N must be an array of real non-negative integers.
Error in piram (line 7)
sumpart=symsum((factorial(4*k)*(1103+26390*k))/(((factorial(k))^4)*(396^(4*k))),k,0,inf);
Error in ProgramPi (line 34)
piram
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
편집: Jacob Oleshchuk 2018년 11월 27일
I have what you have in your picture my guy, are you sure you didn't fix something subconciously?
madhan ravi
madhan ravi 2018년 11월 27일
편집: madhan ravi 2018년 11월 27일
I didn‘t have any trouble getting the result after running your code , ok type whos k in command window and paste the result here. or try
syms k positive
leaving the rest of the code unchanged
>> whos k
>> piram
Error using factorial (line 20)
N must be an array of real non-negative integers.
Error in piram (line 7)
sumpart=symsum((factorial(4*k)*(1103+26390*k))/(((factorial(k))^4)*(396^(4*k))),k,0,inf);
>> whos k
>>
i get nothing
madhan ravi
madhan ravi 2018년 11월 27일
I have no clue what mistake you did
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
i'm 99% sure the mistake is in my factorial somewhere
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
Seeing as that it keeps telling me,
Error using factorial (line 20)
N must be an array of real non-negative integers.
madhan ravi
madhan ravi 2018년 11월 27일
whos factorial
which -all factorial
in command window what does it show?
Jacob Oleshchuk
Jacob Oleshchuk 2018년 11월 27일
C:\Program Files\Matlab\R2018a\toolbox\matlab\specfun\factorial.m
Did you try
syms k positive %?
What shows up for
which factorial(k)
Question: is it possible that you have Maple installed but not the MATLAB Symbolic Toolbox ?
madhan ravi
madhan ravi 2018년 11월 27일
@Jacob please respond to sir Walters question

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2018a

질문:

2018년 11월 27일

댓글:

2018년 11월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by