Summation Using For Loop

조회 수: 9 (최근 30일)
vaninea
vaninea 2017년 3월 11일
댓글: vaninea 2017년 3월 12일
I am having a hard time solving the following problem:
Here is what I have (for n=10) and I cannot for the life of me get the correct output, which should be 3.14 with a bunch of numbers after it.
clc,clear
format long
ESpi=0;
for k=0:10
ESpi=ESpi+[(-1)^k/(2*k+1)^3];
end
ESpi

채택된 답변

David Goodmanson
David Goodmanson 2017년 3월 11일
Hi vaninea, Don't forget that you are calculating pi^3/32, not pi! Espi equals (appoximately) pi^3/32, so you need to work back from that in order to get to(approximately) pi.
  댓글 수: 1
vaninea
vaninea 2017년 3월 12일
Thanks. Your hint helped a lot. I added a small piece of code to my last line and was able to get the answer. Much appreciated!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by