Here is what I have so far:
function numberPI=(-1^n)*1/(2*n+1)*3^n
s=0;
n=input('enter value of n= ');
for i=1:n
s=s+i
numberPI
end
disp(['numberPI= ',num2str(numberPI)]);

댓글 수: 1

Dorothy Carter
Dorothy Carter 2015년 11월 8일
function numberPI s=0; n=input('enter value of n= '); for i=1:n s=s+i; numberPI=sqrt(12)* 1./((2*n+1).*(-3).^n; end disp(['numberPI= ',num2str(numberPI)]); Still an error.

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

 채택된 답변

Real Name
Real Name 2015년 11월 8일

0 개 추천

Are you attempting to use the Leibniz series to approximate pi? That formula you have is not correct.

댓글 수: 2

Dorothy Carter
Dorothy Carter 2015년 11월 8일
편집: Dorothy Carter 2015년 11월 8일
What is the formula then? That was what I was given Changed script: function numberPI s=0; n=input('enter value of n= '); for i=1:n s=s+i; numberPI=sqrt(12)* 1./((2*n+1).*(-3).^n; end disp(['numberPI= ',num2str(numberPI)]); Still an error.
Real Name
Real Name 2015년 11월 9일
편집: Real Name 2015년 11월 9일
The formula is given here:
https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80
SUM (-1)^n/(2n+1) = pi/4
So make sure to multiply the final result by 4. I'm not sure why you were given that formula. You should confirm with whomever your instructor is.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

질문:

2015년 11월 8일

편집:

2015년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by