Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am working on an example from a book (An Engineer's Guide to Mathematica). The following code is in the book:

terms=1+Accumulate[2. Table[1/(1+(2 n)ˆ2),{n,1,500}]]; 
n={ 50,100,200,500} ;
exact=π/2. Coth[π/2.];
pd=100. (exact-p)/exact;
TableForm[{ { n,p,pd} } ,TableHeadings->{ None,{ "N","s",
"% diff"}}]

The output is supposed to look like this:

N s %diff

50 1.70279 0.578059

100 1.70771 0.290481

200 1.71019 0.145605

500 1.71169 0.058329

But I do not get this output. The columns for p and pd are not evaluated, rather in the output I get long many series. I cannot see why this is happening. This is a confounding problem for me as I am trying to learn the platform.

share|improve this question

closed as off-topic by RunnyKine, xzczd, m_goldberg, Yves Klett, Mr.Wizard Aug 8 '14 at 4:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – RunnyKine, xzczd, m_goldberg, Yves Klett, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

The problem is that you may have copied the input directly from the book so your caret (power sign) was not what it was meant to be. Type the input yourself and it will work fine. –  RunnyKine Aug 8 '14 at 2:50

1 Answer 1

up vote 1 down vote accepted

There is a problem with the entry for terms. Retype the entry and it will work properly as below.

terms = 1 + Accumulate[2. Table[1/(1 + (2 n)^2), {n, 1, 500}]];

n = {50, 100, 200, 500};

p = terms[[n]];

exact = \[Pi]/2. Coth[\[Pi]/2.];

pd = 100. (exact - p)/exact;

TableForm[{{n, p, pd}}, TableHeadings -> {None, {"N", "s", "% diff"}}]

enter image description here

share|improve this answer
Awesome thanks! I'll have to be careful about this kind of stuff in the future. –  prometheus Aug 8 '14 at 3:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.