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.
How do I approximate the value of pi
    조회 수: 8 (최근 30일)
  
       이전 댓글 표시
    
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)]);
채택된 답변
  Real Name
      
 2015년 11월 8일
        Are you attempting to use the Leibniz series to approximate pi? That formula you have is not correct.
댓글 수: 2
  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개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!