bc: A Handy Utility

Mr. McAndrew shows us how the bc command can be used for prototyping numerical algorithms.
Conclusion

In my opinion, bc is a real find: it is small, efficient, self-contained and an extremely useful utility. It is not to be considered a replacement for a good fast programming language such as C, C++ or FORTRAN. But as a means for quickly prototyping numerical algorithms before coding them in a high-level language, it is excellent.

Resources

Alasdair McAndrew lives in Melbourne, Australia, with his wife, three young children and a grumpy cat. He is a Senior Lecturer at Victoria University of Technology, where he teaches mathematics and computing. He is an enthusiastic and satisfied user of Linux, and has been since kernel 0.99; currently he is running Linux on both a desktop and a laptop. He enjoys trawling the Internet for Linux software suitable for children, and when he has time, playing the viola da gamba.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

If you are running the

HL's picture

If you are running the "Hofstadter's chaotic function" with the remainder part, please notice that the BC-utility has a bug with the -l option. It works fine if you use only "bc"-command, instead of "bc -l".

Tested on Ubuntu 9.04.

Clarification about "bc -l"

HL's picture

If you try the code with "bc -l", please note that you must set "scale=0". Otherwise, things such as modulo may seem to work unexpectedly. More here, accessed 28th August 2009 10:14, http://en.wikipedia.org/wiki/Bc_programming_language#Standard_library_fu....

Small notice. When you

HL's picture

Small notice.

When you copy-paste the amicable-code, remove the enter like:

define amicable(m) {
for (j=1;j<=m;j++)
if (sf(sf(j))==j && sf(j)!=j && j

Small error in the code: for

Anonymous's picture

Small error in the code:

for (i=1; i<=100; i++) {
print h[i]," ";
if (i%10==0) print "\n;"
}

The "\n;" should be "\n"; .

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions