Jump to content

Jensen's Device: Difference between revisions

m
no edit summary
m (adding maxima)
mNo edit summary
Line 404:
print(sum("i", 1, 100, "1/i"))
</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}}==
Line 433 ⟶ 418:
<pre>
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>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.