Not sure why the loop's not working??
조회 수: 1 (최근 30일)
이전 댓글 표시
the loop parts suppose to repeat until (abs((a+b)^2/(4*t)-pi)<= thres).
a=1;
b=1/sqrt(2);
t=1/4;
x=1;
thres = 0.001;
while abs((a+b)^2/( 4*t )-pi) > thres
y=a;
a=(a+b)/2;
b=sqrt(b)*sqrt(y);
t=t-(x)*(y-a)^2;
x=2*x;
if (abs((a+b)^2/(4*t)-pi)<= thres)
break
mypi= (a+b)^2/(4*t);
end
end
댓글 수: 2
채택된 답변
Matthew Doveton
2013년 5월 13일
mypi is never reached due to the positioning of the break statement, should be:
a=1; b=1/sqrt(2); t=1/4; x=1; thres = 0.001;
while abs((a+b)^2/( 4*t )-pi) > thres
y=a;
a=(a+b)/2; b=sqrt(b)*sqrt(y);
t=t-(x)*(y-a)^2; x=2*x;
if (abs((a+b)^2/(4*t)-pi)<= thres)
mypi = (a+b)^2/(4*t);
break
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!