home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Press 1997 July
/
Sezamfile97_1.iso
/
msdos
/
misc
/
sm30a.a03
/
SYMBMATH.H31
< prev
next >
Wrap
Text File
|
1993-11-07
|
4KB
|
115 lines
4. Examples
In the following examples, a line of "IN: " means input, which
you type in the Input window, then leave the Input window by pressing
<Esc>, finally run the program by the command "Run"; while a line of
"OUT: " means output. You will see both input and output are displayed
on two lines with beginning of "IN: " and "OUT: " in the Output window.
You should not type the word "IN: ". Some outputs may be omitted on the
examples. # is a comment statement.
You can split a line of command into multi-lines of command by
the comma ,. The comma without any blank space must be the last character
in the line.
Note that you should not be suprised if some functions in the
following examples are not working when their libraries are not in the
default directory or missing.
4.1 Calculation
SymbMath gives the exact value of calculation when the switch
numeric := off (default), or the approximate value of numeric
calculation when the switch numeric := on or by num().
Mathematical functions are usually not evaluated until by
num() or by setting numeric := on.
SymbMath can manipulate units as well as numbers, be used as
a symbolic calculator, and do exact computation. The range of real
numbers is from -infinity to +infinity, e.g. ln(-inf), exp(inf+pi*i),
etc. SymbMath contains many algorithms for performing numeric
calculations. e.g. ln(-9), i^i, (-2.3)^(-3.2), 2^3^4^5^6^7^8^9, etc.
Note that SymbMath only gives a principle value if there
are multi-values, except for the solve() and root().
Example 4.1.1.
exact and numeric calculations of 1/2 + 1/3.
IN: 1/2+1/3 # exact calculation
OUT: 5/6
IN: num(1/2+1/3) # numeric calculation
OUT: 0.8333333333
Evaluate the value of the function f(x) at x=x0 by f(x0).
Example 4.1.2.
evaluate sin(x) when x=pi, x=180 degree, x=i.
IN: sin(pi), sin(180*degree)
OUT: 0, 0
IN: sin(i), num(sin(i))
OUT: sin(i), 1.175201 i
Example 4.1.3.
Set the units converter from the minute to the second, then calculate
numbers with different units.
IN: minute:=60*second
IN: v:=2*meter/second
IN: t:=2*minute
IN: d0:=10*meter
IN: v*t+d0
OUT: 250 meter
Evaluate the expression value by
subs(y, x = x0)
Example 4.1.4.
evaluate z=x^2 when x=3 and y=4.
IN: z:=x^2 # assign x^2 to z
IN: subs(z, x = 3) # evaluate z when x = 3
OUT: 9
IN: x:=4 # assign 4 to x
IN: z # evaluate z
OUT: 16
Note that after assignment of x by x:=4, x should be cleared from
assignment by clear(x) before differentiation (or integration) of the
function of x. Otherwise the x values still is 4 until new values
assigned. If evaluating z by the subs(), the variable x is
automatically cleared after evaluation, i.e. the variable x in subs()
is local variable. The operation by assignment is global while the
operation by internal function is local, but operation by external function
is global. This rule also applies to other operations.
The complex numbers, complex infinity, and most math functions
with the complex arguement can be calculated.
Example 4.1.5.
IN: sign(1+i), sign(-1-i), i^2
OUT: 1, -1, -1
Example 4.1.6.
IN: exp(inf+pi*i)
OUT: -inf
IN: ln(last)
OUT: inf + pi*i
The built-in constants of inf or -inf, zero or -zero, and
discont or undefined can be used as numbers in calculation of
expressions or functions.
4.1.1 Discontinuity and one-sided value
Some math functions are discontinuous at x=x0, and only have
one-sided function value. If the function f(x0) gives the discont as its
function value, you can get its one-sided function value by f(x0-zero)
or f(x0+zero).
Example 4.1.7.
IN: f(x_) := exp(1/x) # define function f(x)
IN: f(0)
OUT: discont # discontinuity at x=0
IN: f(0-zero) # left-sided value at x=0-
OUT: 0
IN: f(0+zero) # right-sided value at x=0+
OUT: inf
4.1.2 Undefined and indeterminate form
If the function value is undefined, it may be indetermate form
(e.g. 0/0, inf/inf), you can evaluate it by lim() (see Chapter 4.4 Limits).