home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
utility
/
sm22a.zip
/
SYMBMATH.H14
< prev
next >
Wrap
Text File
|
1993-04-21
|
9KB
|
288 lines
8. Packages
A package is a SymbMath program file for special use.
In order to expand the special ability of SymbMath, some
packages should be included in the user program by
include('filename')
The filename is any MS-DOS filename.
It is recommended that the filename is the same as the function
name in the program file, and the extension of the filename is .sm in
order to remember easily the name of the package. e.g. inte.sm is the
filename of the integral package as the name of integral function is
inte().
After including the package, users can call the functions in
the package from their program.
The include command must be in a single line anywhere.
Many packages can be included at a time, however, all names of
the variables are public and name conflicts must be avoided.
Alternately, a part of the package file rather than the whole
package file can be copied into the Edit window by pressing <F7>
(external copy) in order to save memory space.
There are many packages. The following are some of them.
Table 8.1 Packages
------------------------------------------------------------------------
File Name Package Function
init.sm initial package when running the program in
the Edit window. It contains switches on the
default status.
plot.sm plotting functions.
listplot.sm plotting a list of data.
d.sm derivatives.
inte.sm integrals.
--------------- shareware version only has above packages --------------
units.sm an units conversion.
trig.sm reduction of trig functions.
hyperbol.sm reduction of hyerbolic functions.
dt.sm total derivatives.
NInte.sm numeric integration.
NSolve.sm numeric solver of equation.
ODE.sm ordinary differential equation.
gamma.sm gamma function.
ei.sm exponential integral function.
series.sm Taylor series.
sum.sm symbolic sum.
InfSum.sm infinite sum.
chemical.sm the atomic weight of chemical elements.
inorgani.sm inorganic chemical reactions.
-----------------------------------------------------------------------
8.1 Initial Package
---------------------------------------------------------------------
# The initial package init.sm
output=off
numerical=off
expand=off
sum(y_,x_,a_,b_) := sum(y,x,a,b,1)
prod(y_,x_,a_,b_) := prod(y,x,a,b,1)
list(y_,x_,a_,b_) := list(y,x,a,b,1)
table(y_,x_,a_,b_) := table(y,x,a,b,1)
table(y_,x_) := table(y,x,-5,5,1)
degree=pi/180
0!=1
inf!=inf
sgn(0)=0
sgn(zero)=1
sgn(e)=1
sgn(pi)=1
sgn(inf)=1
abs(zero)=zero
abs(e)=e
abs(pi)=pi
abs(inf)=inf
ln(0)=-inf
ln(inf)=inf
include('plot.sm')
# include('d.sm')
block(output=basic,null)
end
---------------------------------------------------------------------
When running the program in the Edit window, SymbMath
automatically first includes (or runs) the initial package 'init.sm'.
The commands in the 'init.sm' package seems the SymbMath system
commands. You can include other packages (e.g. d.sm) in the initial
package 'init.sm' so the derivatives table in the package 'd.sm' seems
to be in SymbMath system. Doing this is by changing the comment
statement in the last third line
# include('d.sm')
to include statement
include('d.sm')
8.2 Derivative Package
The package 'd.sm' is extention of the d(f(x),x) function.
8.3 Total Derivative Package
The package 'dt.sm' is for the total derivative function
dt(f(x,y),x,y).
Example:
Input:
include('dt.sm')
dt(x*y, x, y)
end
Output:
y*d(x) + x*d(y)
8.4 Integral Package
The package 'inte.sm' is the extention of the function inte(f(x),x).
8.5 Numeric Integration Package
The function
ninte(y, x from x0 to x1)
in the package 'NInte.sm' can do numerical integration.
Example 8.5.1. Compare numerical and symbolic integrations
for 4/(x^2+1) with respect to x taken from x=0 to x=1.
Input:
include('NInte.sm')
ninte(4/(x^2+1), x from 0 to 1)
num(inte(4/(x^2+1), x from 0 to 1))
end
Output:
done
3.1415
3.1416
8.6 Numerical Solving
The function
nsolve( f(x) === x, x, x0)
in the package 'NSolve.sm' can numerically solve an algebraic equation
with an initial value x0.
Example 8.6.1. solve the equation sin(x) === 1 with x0=1.
Input:
include('NSolve.sm')
nsolve( sin(x) === 1, x, 1)
end
Output:
done
1.5364150214
8.7 Series Package
The series package 'Series.sm' has a function series() for the
Taylor series at x=0:
You can call the function
series(f(x), x, order)
series(f(x), x)
to find the Taylor series. The arguement (order) is optional and
defaults to 6.
Example 8.7.1. Find the power series expansion for cos(x)
about the point x=0 to order x^4.
Input:
include('series.sm')
series(cos(x), x, 4)
end
Output:
1 - 1/2*x^2 + 1/24*x^4
8.8 Infinite Sum Package
The infinite sum package 'InfSum.sm' has a function
infsum(f(x),x)
to find the infinite sum, sum(f(x), x from 0 to inf).
Example:
Input:
include('infsum.sm')
infsum(1/n!, n)
end
Output:
e
8.9 Chemical Calculation Package
SymbMath recognizes 100 symbols of chemical elements and
converts them into their atomic weights after the chemical package of
'Chemical.sm' is included.
Example 8.9.1. Calculate the weight percentage of the
element C in the molecule CH4.
Input:
include('chemical.sm')
numerical=on
C/(C+H*4)*100*%
end
Output:
done
numerical = on
74.868 %
Example 8.9.2. Calculate the molar concentration of CuO when
3 gram of CuO is in 0.5 litre of a solution.
Input:
include('chemical.sm')
numerical=on
g=1/(Cu+O)*mol
3*g/(0.5*l)
end
Output:
0.07543*mol/l
8.10 Chemical Reactions Package
SymbMath can provide the answers for inorganic chemical
reactions after the inorganic reaction package "Inorgani.sm" is included.
Example 8.10.1. What are the products when the reactors are
HCl + NaOH ?
Input:
include('inorgani.sm')
HCl+NaOH
end
Output:
H2O + NaCl
8.11 Plot Function Package
---------------------------------------------------------------------
# The plot function package plot.sm
# to plot a function.
# plot(x^2, x) # plot the function of x^2
# plot(x^2, x,-6,6) # plot the function of x^2 from x=-6 to x=6
# end
output=off
plot(y_,x_,x1_,x2_,dx_) := block(openfile('symbmath.out'),
table(y,x,x1,x2,dx),
closefile('symbmath.out'),
system(plotdata))
plot(y_,x_,x1_,x2_) := plot(y,x,x1,x2,(x2-x1)*0.5)
plot(y_,x_) := plot(y,x,-5,5,0.5)
output=on
end
----------------------------------------------------------------------
If SymbMath is interfaced with the software PlotData, SymbMath
produces the data table of functions, and PlotData plots from the
table. So SymbMath seems to plot the function. This interface can be
used to solve equations graphically.
In the plot package 'plot.sm' the funcion
plot(y, x, x1, x2, dx)
first open a file 'SymbMath.Out' for writing, then write the data table
of the function y into the file 'SymbMath.out', then close the file,
and finally automatically call the software PlotData to plot. After it
exits from PlotData, it automatically return to SymbMath.
The functions
plot(y, x)
plot(y, x from xmin to xmax)
call the function plot(y,x,x1,x2,dx)
e.g. plot x^2.
Input:
plot(x^2, x)
end
in the software PlotData, just select the option to read the file
'SymbMath.out' and to plot. PlotData read the data in the SymbMath
format without any modification (and in many data format).
In PlotData,
in the main menu:
1 <Enter>
in the read menu:
1 <Enter>
<Enter>
in the main menu:
2 <Enter>
in the graph menu:
1 <Enter>
where <Enter> is the <Enter> key.
Refer to PlotData for detail.
Note that if your monitor is Hercules, you must load the
MSHERC.COM program as a TRS program before you run PlotData.
Otherwise you will get Error when you plot.
8.12 List Plot Package
----------------------------------------------------------------------
# the list plot package 'listplot.sm'
# to plot a list of data.
# listplot([1,2,3,4,5,4,3,2,1])
# end
output=off
listplot(y_) := if(islist(y), block(yy=y, length=length(yy),
openfile('symbmath.out'),
table(yy[xx],xx,1,length),
closefile('symbmath.out'),
system(plotdata) ))
output=on
end
---------------------------------------------------------------------