Adviser to Unix Explanations bc
08 February 15:32
bc is an arbitrary-precision calculator language. The arbitrary-precision agency that numbers can accommodate absolute digits (limited by memory); alotof additional languages absolute numbers to eight bytes at most. For addition, subtraction, and multiplication, there is absolute precision. Analysis stops afterwards a assertive amount of decimal places (usually 0 or 20), so bc is generally bad with actual baby numbers (like 10e-44).
bc is generally alleged using the -l option, which endless the accepted library (which mostly contains accurate functions) and sets the amount of decimal places for analysis to 20. (Doing accurate with the absence attention of 0 decimal places is not so useful.)
This is an archetype of a user starting bc, accomplishing two calculations, and exitting with quit. Agenda that acute ^D (control-D) aswell exits.
$ bc -l
3 + 4
7
2 / 5
.40000000000000000000
quit
$
This Software accouterments Simpsons aphorism for integration. The action accommodate approximates the definate basic from a to b using n ambit sections. The blueprint for simpson is taken from Simpsons rule. This archetype integrates the sine function, but altered functions can be acclimated by replacing f.
ascertain f(x)
ascertain simpson(a,b)
ascertain integrate(a,b,n)
acknowledgment result;
}
Put this in a file, say simpson, amount it, and accommodate f from 0 to pi (pi is 4 $ bc -l simpson
integrate(0, 4 2.00000000067647189101
^D
Now explain these appearance so users can accept the script.
bc is generally alleged using the -l option, which endless the accepted library (which mostly contains accurate functions) and sets the amount of decimal places for analysis to 20. (Doing accurate with the absence attention of 0 decimal places is not so useful.)
This is an archetype of a user starting bc, accomplishing two calculations, and exitting with quit. Agenda that acute ^D (control-D) aswell exits.
$ bc -l
3 + 4
7
2 / 5
.40000000000000000000
quit
$
This Software accouterments Simpsons aphorism for integration. The action accommodate approximates the definate basic from a to b using n ambit sections. The blueprint for simpson is taken from Simpsons rule. This archetype integrates the sine function, but altered functions can be acclimated by replacing f.
ascertain f(x)
ascertain simpson(a,b)
ascertain integrate(a,b,n)
acknowledgment result;
}
Put this in a file, say simpson, amount it, and accommodate f from 0 to pi (pi is 4 $ bc -l simpson
integrate(0, 4 2.00000000067647189101
^D
Now explain these appearance so users can accept the script.
|
Tags: numbers, places simpson, integrate, precision, define, places, numbers, decimal, , decimal places, |
Also see ...
PermalinkArticle In : Computers & Technology - Unix