⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0259-0263.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:






<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Learning Math and Financial Tools</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311623 //-->

<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->

<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=17 //-->

<!-- PAGES=0259-0270 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="../ch16/0256-0258.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0264-0266.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-259"><P>Page 259</P></A>









<H3><A NAME="ch17_ 2">

Hour 17</A></H3>



<H2>

<A NAME="ch17_ 3">

Learning Math and Financial<BR>

Tools

</A>

</H2>





<P>This lesson is an introduction to some of the mathematical and financial

tools available for Linux. This hour shows you calculators, spreadsheets,

and graphic modeling programs, and  points you to sources where you can

find even more programs. Whether you're only interested in setting up

simple single-screen spreadsheets, or would rather plot detailed maps using

200 megabytes of cartographic data from the U.S. Geologic Survey, you'll

find Linux tools to help you get started.

</P>





<P>The hour begins with a discussion of some calculators and

calculating languages, and introduces you to just some of the Linux

spreadsheet programs, followed by a discussion of modeling programs, such as

gnuplot. This hour can't cover all the of the more than 1,500 scientific applications

for Linux, but if you have an interest in other fields such as artificial

intelligence, astronomy, biology, chemistry, database systems, electronics, linear

algebra, physics, or raytracing, you can find tools for Linux to help you.

</P>









<A NAME="PAGENUM-260"><P>Page 260</P></A>











<H3><A NAME="ch17_ 4">

Calculators

</A></H3>





<P>This section introduces you to several Linux calculators. You'll find some of these

handy when you pay bills, cook, or even travel. Some of these calculators work from the

command line, and others run under the X Window System.

</P>





<H4><A NAME="ch17_ 5">

Doing Desk Calculations with the dc Command

</A></H4>





<P>The dc (desk calculator) command is a command-line calculator that uses reverse

Polish notation, or RPN, to perform calculations, and has more than 30 different operators

and internal commands.

</P>





<P>The dc command, found under the /usr/bin directory, is easy to use:

</P>



<!-- CODE //-->

<PRE>

# dc

44

55

+

p

99

q

</PRE>

<!-- END CODE //-->





<P>The example shows that to add two numbers, you first enter the numbers,

then enter the operator, then use the p command to print the value placed on the stack by the

addition operator. The q command quits the dc program. This method of performing

calculations is not as inconvenient as you may think. For example, suppose that you're going

through the checks you've written during the month, and you want to check your

written calculations. Using the dc command, you can enter

</P>



<!-- CODE //-->

<PRE>

# dc

2500.00

49.95

-

p

2450.05

32.18

-

p

2417.87

q

</PRE>

<!-- END CODE //-->





<P>You started by entering a $2500.00 balance, then entered $49.95 as the first

check, followed by the subtraction operator, or minus sign. The

p command prints the result, and the next current balance of $2450.05 is maintained on the stack. You can also use the

dc command to read files of calculations instead of typing commands at your terminal,

and it has 256 different registers, or temporary storage areas for your calculations. See the

dc command's manual page for more information and other features.

</P>







<A NAME="PAGENUM-261"><P>Page 261</P></A>











<H4><A NAME="ch17_ 6">

Calculating with the X11 xcalc Client

</A></H4>





<P>The xcalc client is one of the more familiar graphic calculators (see Figure 17.1), and

comes with the XFree86 X Window System. The xcalc command, found under the

/usr/X11R6/bin directory, has only two command-line options,

-stipple, and -rpn. The -stipple option merely colors the background of

xcalc's face, whereas the -rpn option tells the

xcalc command to use rpn for doing calculations, and changes its appearance.

</P>





<P>You must be running X11 in order to use the

xcalc command. You can use your mouse or the keyboard to enter numbers and perform calculations. To use it in its normal mode

with the -stipple option, type

</P>



<!-- CODE SNIP //-->

<PRE>

# xcalc -stipple &amp;

</PRE>

<!-- END CODE SNIP //-->





<P>Figure 17.1.<BR>

The xcalc calculator.<BR>

<a href="javascript:displayWindow('images/ch17fg01.jpg', 288, 216)"><img src="images/tn_ch17fg01.jpg"></a><BR>

</P>





<P>To use the xcalc command as an rpn calculator, type

</P>



<!-- CODE SNIP //-->

<PRE>

# xcalc -rpn -stipple &amp;

</PRE>

<!-- END CODE SNIP //-->





<P>You can customize nearly any aspect of xcalc by editing its defaults file,

Xcalc, which is found under the

/usr/X11R6/lib/X11/app-defaults directory. See the

xcalc manual page for more information.

</P>





<H4><A NAME="ch17_ 7">

Three Calculators in One: dtcalc

</A></H4>





<P>The dtcalc calculator, part of Red Hat Software, Inc.'s Common Desktop Environment,

or CDE (see Hour 8, &quot;Exploring Other X11 Window Managers&quot;), offers a variety of

features

</P>



<A NAME="PAGENUM-262"><P>Page 262</P></A>







<P>

and can emulate a logical, scientific, or financial calculator. Although

dtcalc does not have as much register storage as the

dc command, you can use your mouse or keyboard to

enter data, just as you can with xcalc. Figure 17.2 shows the

dtcalc calculator.

</P>



<P>Figure 17.2.<BR>

The dtcalc calculator,<BR> part of the Common<BR> Desktop

Environment<BR> for the X Window<BR> System, can emulate<BR> three different

calcula-<BR>

tors.<BR>

<a href="javascript:displayWindow('images/ch17fg02.jpg', 288, 216)"><img src="images/tn_ch17fg02.jpg"></a><BR>

</P>



<P>You can perform calculations in binary (base 2), octal (base 8), decimal, and

hexadecimal (base 16). You can also define your own functions and constants. Like most other

CDE applications, dtcalc has extensive and context-sensitive help. For more information about CDE, see Hour 6, &quot;Using the Shell.&quot;

</P>





<H4><A NAME="ch17_ 8">

Performing Unit Conversions with the units Command

</A></H4>

<P>If you've ever had trouble remembering the formulas to convert miles to meters, or

cups to gallons, you'll really like Adrian Mariano's units command, which you'll find under the 

/usr/bin directory. Want to know how many furlongs per mile? How about how many

acres in a square mile?

</P>





<P>One way to use the units command is from the command line, for example:

</P>



<!-- CODE SNIP //-->

<PRE>

# units floz gallon

        * 0.0078125

        / 128

</PRE>

<!-- END CODE SNIP //-->





<P>This simple example shows how to find out how many fluid ounces are in a gallon.

You see that there are 128, and that a fluid ounce is less than one-hundredth of a gallon.

Although using the command line is handy for quick conversions, you can also run a series of

queries as follows:

</P>



<!-- CODE SNIP //-->

<PRE>

# units

</PRE>

<!-- END CODE SNIP //-->







<A NAME="PAGENUM-263"><P>Page 263</P></A>





<!-- CODE //-->

<PRE>

501 units, 41 prefixes



You have: mile*mile

You want: acre

        * 640

        / 0.0015625

You have: mile2

You want: acre

        * 640

        / 0.0015625

You have: mile^2

You want: acre

        * 640

        / 0.0015625

You have: mile

You want: furlong

        * 8

        / 0.125

You have: 100 fathoms

You want: feet

        * 600

        / 0.0016666667

...

</PRE>

<!-- END CODE //-->





<P>In the interactive mode, you can ask units for any number of conversions. The

units command works by reading its library of conversions from the file

units.lib under the /usr/lib directory. As you can see, you can use different notations to indicate amounts to be

converted. Another interesting feature is that

units can also perform currency conversions, for example:

</P>



<!-- CODE SNIP //-->

<PRE>

# units dollar yen

        * 107.52688

        / 0.0093

</PRE>

<!-- END CODE SNIP //-->





<P>Note that this may not be entirely true, as currency values change daily. You can edit

the units.lib file and insert not only current currency values, but also prices for gold,

silver, platinum, or pork bellies. See the units manual page for more information.

</P>





<H4><A NAME="ch17_ 9">

Programming Calculators with the bc Language Interpreter

</A></H4>





<P>The bc command is an interpreter for a calculator language. You can use this

command, by Philip Nelson, to write calculator programs while

bc is running, or have bc run the program after it starts. The

bc language has nearly 40 operators, functions, and

programming logic keywords. Although this section doesn't go into how to program in

bc, it shows you how a simple checkbook balancing program (from

bc's manual page) can work like the earlier example for the

dc command. If you'd like to try this program, see the

bc manual page, then type the program into a file using your favorite text editor. You can run it with

</P>



<!-- CODE SNIP //-->

<PRE>

# bc nameofyourfile

</PRE>

<!-- END CODE SNIP //-->





<P>The bc command will start by reading in its program, and present the following:

</P>



<P><CENTER>

<a href="../ch16/0256-0258.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0264-0266.html">Next</A>

</CENTER></P>











</td>
</tr>
</table>

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -