Jensen's Device: Difference between revisions

Content added Content deleted
m (adding maxima)
mNo edit summary
Line 404: Line 404:
print(sum("i", 1, 100, "1/i"))
print(sum("i", 1, 100, "1/i"))
</lang>
</lang>

=={{header|Mathematica}}==

<lang Mathematica>sum[term_, i_, lo_, hi_] := Block[{temp = 0},
Do[temp = temp + term, {i, lo, hi}];
temp];
SetAttributes[sum, HoldFirst];</lang>

Output:
<pre>In[2]:= sum[1/i, i, 1, 100]
Out[2]= 14466636279520351160221518043104131447711/2788815009188499086581352357412492142272

In[3]:=N[sum[1/i, i, 1, 100]]
Out[3]:=5.18738
</pre>


=={{header|M4}}==
=={{header|M4}}==
Line 433: Line 418:
<pre>
<pre>
5142
5142
</pre>

=={{header|Mathematica}}==

<lang Mathematica>sum[term_, i_, lo_, hi_] := Block[{temp = 0},
Do[temp = temp + term, {i, lo, hi}];
temp];
SetAttributes[sum, HoldFirst];</lang>

Output:
<pre>In[2]:= sum[1/i, i, 1, 100]
Out[2]= 14466636279520351160221518043104131447711/2788815009188499086581352357412492142272

In[3]:=N[sum[1/i, i, 1, 100]]
Out[3]:=5.18738
</pre>
</pre>