Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://hea-www.harvard.edu/~alexey/calc-examples.html
Дата изменения: Unknown Дата индексирования: Mon Oct 1 21:30:55 2012 Кодировка: Поисковые слова: clouds |
% calc 2*2-8+16.789/3 + 3**2 10.5963or more complex expressions
% calc (3**2/4)**(1/3) 1.31037and use functions (*See notes on functions):
% calc sin(atan(0.95))*sqrt(4.32) 1.43154or factorials (*See notes on factorials):
% calc 5! * 6! 86400Arithmetic conventions are respected: 3sqrt(2) [or 3 sqrt(2)] <=> 3*sqrt(2)
% calc asind(0.5sqrt(2)) # arcsin of sqrt(2)/2 in degrees 45Users are expected to apply some common sense and not to use arithmetic expressions which can be interpretted as functions: 10(mp+me), (mp+me)c**2 are OK, but c(mp+me) (meaning c*(mp+me)) is not.
You can use some constants (*See notes on constants):
% calc sin(30deg); calc asin(sqrt(2)/2)/deg # sin and asin in degrees 0.5 45 % calc 1.e38/(4pi*(2kpc)**2) # Cyg X-1 flux in ergs/s/cm**2 2.08944e-07 % calc Lsun/(4pi*(150e6 km)**2)/(W/m**2) # Solar flux on Earth 1353.17 # (Watt per square meter) % calc Rsun/c # Solar radius in light seconds 2.32157 % calc 0.0232*c/(50 km/s/Mpc)/Mpc # Distance to the Coma cluster (z=0.0232) 139.104 # in Mpc, assuming H0=50. % calc 10kpc/sqrt(2*10keV/mp)/year # How many years does it take a 10 keV 7.06453e+06 # proton to travel 10 kpc? % calc 800cm**2/(pi*(60inch)**2/4) # Chandra effective area at 1 keV compared 0.0438561 # to the area of the FLWO 60" telescopeAlthough a space is not required between a number and a constant, it is mandatory between a constant and a number: 4pi*10**2 and 4pi 10**2 are valid, but 4pi10**2 is not.
In fact, you can use calc to find the values of constants or do some units conversion or both:
% calc kpc; calc me # kpc in cm and electron mass in grams 3.08568e+21 9.10939e-28 % calc mp/lb # proton mass in pounds 3.6875e-27 % calc 85mph/(km/hr) # Tell your European friend what you've 136.794 # got your recent speeding ticket for. But 85mph/(km/h) would be a gross underestimate because of quantum effects.You can even write simple programs.
% calc 'p=0.1; n=3; (p**n/n!)*exp(-p)' 0.000150806Note that the body of the program should be enclosed into single quotes. You can use lower-case, single-character variables except for c,e,h,k,m,s which are reserved for constants. Statements should be separated by semicolon. Only the result of the last expression is printed unless you explicitly use `print' --- but then it is easier to write a new Perl script.
Functions:
All math. functions allowed in Perl (abs, atan2,
cos, exp, int, log,
rand, sin, sqrt) plus
ln - natural log
lg - log_10
r2d - convert radians to degrees
atan, tan, acos, asin
sind, cosd, tand, asind, acosd,
atand - degree-based trigonometric functions
[note that you also can use the `deg' constant:
sind(30) <=> sin(30deg)]
nint - nearest integer
fact - factorial
C(n,k) = n!/(k!*(n-k)!)
Factorials:
When you use `!', you have to put a space after it, otherwise the shell is
likely to mess things up. A safer way to calculate factorials is the
fact()
function. Use C(n,k) to calculate n!/(k!*(n-k)!)
Constants
Use `calc -h' to print out the defined constants.