[100] 001 Chapter 1 Introduction, Tutorial by www.msharpmath.com
[100] 001 revised on 2012.11.26
|
cemmath
The Simple is the Best
|
Chapter 1 Introduction
1-1 Introduction of CEMMATH
1-2 Data Structure in CEMMATH
1-3 Compatibilty with C language
1-4 Auto Tracing of CEMMATH
CEMMATH can be downloaded from www.msharpmath.com and is free to personal users. The main objective of CEMMATH is to help students from middle to graduate school in studying math-related topics. Accordingly, distributing Free Textbooks is one of the most important tasks.
Section 1-1 Introduction of CEMMATH
■ History of Development. The CEMMATH is a product of MSharpMath Inc (www.msharpmath.com) and its core grammar is developed at Seoul National University. The first beta version of CEMMATH (Version beta 1.01) has been released at the end of the year 2009. The beta version of CEMMATH is free to personal users for testing. The current tutorial is mainly for the Window which can be downloaded from the www.msharpmath.com.
The old version for the iOS products (iPad, iPod touch and iPhone) can be downloaded from the Appstore. However, some of grammars have changed in this new PC Version. We are planning to upgrade the iOS versions in the future.
■ Interactive Interpreter. CEMMATH is an interactive interpreter and can be used as a calculator
#> 7 + 5 * 2
ans = 17
In the command-window, a semi-colon ';' is automatically attached to each interactive command. Therefore, a one-line command written in the command-window is executed right after typing a return key. In general, each command must be terminated by a semi-colon (or double semi-colons) as in C-language.
A single semi-colon activates the screen output, whereas double semi-colons suppress the screen output. This can be confirmed by the following three commands
#> 1;
#> 2;;
#> 3;
ans = 1
ans = 3
Note that the second command ‘2;;’ has no screen output.
■ Motive of CEMMATH. CEMMATH has been developed under the ambition that mathematical and engineering problems can be solved in an expression-look-alike manner. For example, a very simple problem of finding root can be written as
Find satisfying the equation near the point
(note that the given equation has many roots)
CEMMATH is innovated to accommodate the keywords relevant to this problem, as listed below
(1) solve
(2)
(3)
(4)
Readers should notice that there is no need of defining any user function such as . Then, it is natural to imagine that the above problem can be solved without establishing a user-function for the equation. This mission is indeed accomplished in CEMMATH by utilizing the concept of Umbrella such that
#> solve .x { pi } ( sin(x) = 0.3 );
ans = 2.8369
Note that the four keywords describing the problem have been judiciously combined to construct an CEMMATH command (of course, in a form of Umbrella).
Another simple example would be to plot curves. The mission is specified below.
Plot curves over a range .
In CEMMATH, the above mission is examined to extract the following keywords
(1) plot
(2)
(3)
Then, the Umbrella ‘plot’ can be innovated such that
#> double y(x) = |x|*sin(x);
#> plot.x(-pi,2*pi) ( y(x), y'(x), y''(x) );
which results in Figure 1. Note that two-slashes ‘//’ are used to make a single-line comment as in the C-language.
Figure 1 plot curves over
Readers would recognize that CEMMATH didn’t employ any matrix and user-defined function to solve the above two problems. Only the concept of Umbrella has been employed. Although the details will be discussed later, readers may note the basic concept of the Umbrella from the following commands and recognize the similarities between several Umbrellas.
#> solve .x{ pi } ( sin(x) = 0.3 ); // root of a single equation
#> solve .x{ 1+10! } ( exp(x)+1 = 0 ); // complex root
#> solve .x.y{ 1,2 } ( y=x+1, y=x*x ); // root of coupled equations
#> plot .x(0,2*pi) ( x*sin(x) ); // curve
#> plot .x(-3,3).y(x*x-9, 4+x) ( (x*x+y*y)*exp(1-x*x-y*y) ); // surface
#> int .t(0,2*pi) ( 1/(13+12*sin(t)) ); // single integration
#> int .x(0,1).y(0,sqrt(x-x*x)) ( x-x*x-y*y ); // double integration
#> int .x(0,3).z(1,x).y(z-x,z+x) ( exp(2*x)*(2*y-z) );
■ Namespace-conserving by the use of dot functions. Most built-in functions in CEMMATH starts with a character dot ‘.’, and are called dot functions. The reason for this is to conserve namespace, i.e. to avoid conflicting names between similar concepts. This namespace-conserving concept of CEMMATH allows users to select the function names as variables at any times. Simply speaking, although a certain built-in function ‘.ftn’ is defined in CEMMATH, the very variable without ‘.’ ( i.e. ‘ftn’ ) is free to users.
In some cases, using a dot function is helpful to understand its mission. For example, the Heaviside function returns 1 if and returns 0 if . It is possible to use a single character 'H' as a name of a dot function
#> H = .H(pi) ; .H(-pi) ; // Heaviside function H(x)
H = 1
ans = 0
■ Concept of Tuple. In CEMMATH, a new concept of tuple is innovated to handle a collection of special structures. The tuple is defined as
( a list of data )
which is apparently the same as the argument list of a function. The simplest usage of the tuple is
#> (x,y,z) = (1,2,3);
x = 1
y = 2
z = 3
which is exactly the same as
#> x = 1; y = 2; z = 3;
However, switching values by
#> (y,z,x) = (x,y,z);
y = 1
z = 2
x = 3
should be written as the following in the C-language
#> s=y; t=z; y=x; z=s; x=t;
The tuple is mostly used to span a one-dimensional array in such a way that
(a,b) .span(n,g=1)
(a,b) .logspan(n,g=1)
(a,b) .step(h) // equivalent to a:h:b
As a collection of objects, the tuple can invoke proper tuple functions such as ‘span, logspan, step’ as shown above.
■ In CEMMATH, a block comment can be made by a pair of ‘/*’ and ‘*/’ as in the C language. A more elegant method for block comments is using a nested pairs of ‘%{‘ and ‘%}’.
Section 1-2 Data Structure in CEMMATH
■ Data Structure. Not only the matrix but also several important data structures are adopted in CEMMATH as built-in nature. The data structures adopted in CEMMATH include
matrix
double
complex
poly
vertex
csys
and so on. It is well understood that the data structure of matrix plays the most crucial role of developing softwares. In CEMMATH, various data structures are adopted to work efficiently with well-accepted structures such as polynomials and vertices in the three-dimensional geometry.
It would be wise to work directly with polynomials instead of functions based on matrix. Also, the vertex class would be convenient in generating 3D meshes. Several data structures are discussed briefly in the below. Detailed description of each data structure is provided in PART 2.
■ Complex. In CEMMATH, both the data types ‘double’ and ‘complex’ are distinguished.
A pure imaginary number is denoted by ‘1!’ not by ‘sqrt(-1)’. This is because that the data type returned by a function ‘sqrt’ depends on the data type of its argument (i.e. -1). Therefore, it should be reminded that ‘sqrt(-1)’ does not return .
A complex number can be created by
z = complex(x,y)
z = x + y!
Both the real and imaginary parts of a complex number are denoted by
z.x
z.y
■ Matrix. A matrix constant is created by a pair of brackets ‘[ ]’
#> [ 1,2,3; 4,5,6];
ans =
[ 1 2 3 ]
[ 4 5 6 ]
A few intrinsic matrices such as the identiy matrix can be created by
%> Namespace conserving built-in functions
#> .I(3,4); // equivalent to .eye(3,4)
ans =
[ 1 0 0 0 ]
[ 0 1 0 0 ]
[ 0 0 1 0 ]
Similary, the following commands are self-explanatory
%> Examples of name-space conserving built-in functions
#> .zeros(2); .ones(2,3);
which yield
ans =
[ 0 0 ]
[ 0 0 ]
ans =
[ 1 1 1 ]
[ 1 1 1 ]
In addition, a special form of generating one-dimensional vectors is
%> Example of spanning matrix
#> 3 : 6 ;
ans =
[ 3 4 5 6 ]
which creates a row vector by incrementing consecutive element by 1.
■ Polynomial. Polynomials are treated in CEMMATH by the declarer ‘poly’. A use of class ‘poly’ enables users to handle polynomials with ease, for example
%> Example of polynomial operation
#> poly(6,5,1) * poly(7,2) + 20 ;
ans = poly( 62 47 17 2 )
results in
A number of special polynomials such as the Tchebyshev, Legendre and binomial polynomials can be generated simply by
%> polynomials in CEMMATH
#> poly.T(5) ;
#> poly.P(5).ratio ;
#> poly.binom(5).iratio ;
ans = poly( 0 5 0 -20 0 16 )
ans = (1/8) * poly( 0 15 0 -70 0 63 )
ans = poly( 0 1/5 -5/12 7/24 -1/12 1/120 )
These can be confirmed from mathematics by
Although discussed later in PART 2, a set of Legendre polynomical can be drawn by
// for.n(a,b) is alternatively written as for(n = a; n <= b; n++) stmt
#> .hold; for.n(0,9) plot.x(-1,1) ( .P_n(x) ); plot;
Figure 2 Legendre polynomials
■ Vertex and Coordinate System. Vertices are treated in CEMMATH by the declarer ‘vertex’. The class ‘vertex’ is particularly useful in handling vertex data in three-dimensional space. Together with the ‘vertex’, a class ‘csys’ is also of crucial importance.
Let us suppose that a point is described in the cylindrical coordinate
with the angle in degree. This point needs to be interpreted by the spherical coordinate
In doing this, we do not employ a function such as ‘cyl2sph’, but utilize a concise expression
%> coordinate system
#> csys.deg; < 2,60,5, cyl > .sph;
// angle in degree. csys.deg is activated
ans = < 5.385 21.8 60 >
which states that . This approach eliminates the need of memorizing many functions such as ‘cart2pol, sph2cyl, cyl2pol, cyl2cart’ etc.
In CEMMATH, conversion from one coordinate system to another coordinate system is simply carried out by
< a,b,c, w_csys > .r_csys
where ‘w_cys’ is a writing coordinate system, and ‘r_csys’ is a reading coordinate system.
Share with your friends: |