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"; .

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix