- How could you make z equal the sequence 1, 3, 5, 7, ..., N?
- How could you make y equal to 4 times the reciprocal of z?
- How could you make x equal to the sum of the "odd" terms of y (i.e., 4/1, 4/5, 4/9, ...) and w equal to the sum of the "even terms of y (i.e., 4/3, 4/7, ...)?
- How can you make v equal to the sum of x and u equal to the sum of w?
- How can you make t be the difference between v and u?
Need help creating a loop
조회 수: 14 (최근 30일)
이전 댓글 표시
Have to create a function with a loop that formulates pi using Leibniz's formula. It has to ask the user for a positive integer n&then calculate pi to n terms (terms being 4=1 , 4/3= 2, 4/5= 3, 4/7= 4, etc..)
Leibniz's formula says that pi= 4-4/3 +4/5 - 4/7 + 4/9 - 4/11 ....
OR
pi/4= 1 - 1/3 +1 /5 - 1/7 + 1/9 - 1/11...
so far, i thought to put:
function pi= pleibniz (n)
for i= 1:n pi/4=
but then i don't know what to do! please help!
댓글 수: 0
채택된 답변
Daniel Shub
2011년 10월 19일
I wouldn't use a loop to do this (and I love loops).
댓글 수: 5
Daniel Shub
2011년 10월 19일
The problem with using a loop for this question is it doesn't really teach you that much about MATLAB. In fact, I would argue that following the steps that I laid out will teach you a lot more about MATLAB than the loop solution.
If you cannot look at Steven's solution and see that it works without running it, you really haven't solved the problem and the homework is only going to get harder.
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!