TeXmacs with CAS |
|
Some famous computer algebra systems (CAS) will be
integrated into the Linux-based platform as CAI tools for
the higher Mathematical courses. The mini memo will cover
some topics as follows:
All the packages will be integrated into bootable Linux
CDROM. In other words, you can continue your paper work in
any place with this platform ( and disk for storing data)
even in net-coffee store. Now, let us explore the journey
and hope you enjoy it!
In this chapter, the individual basic introductions about TeXmacs, core of this book, and the tools about computer algebra systems, CAS, and graph will be given.
This is not only introduction for the people who want to learn how to use TeXmacs, but a note for TeXmacs newbie with some TeX experiences. We try to follow the TeX rules to describe how to making documents. From now on, [content] means the option, content, in the menu bar.
While you execute the TeXmacs from X-terminal, you will see the TeXmacs window. If you are first use this application, the "help" document is also opened in the worksheet windows. Press the button in the menu bar, [File] → [New], to open a new buffer for writing document directly or just as LaTeX doing something "presume document setting":
Generally, part 1 and 2 can be omitted if your do not hear about TeX or simply type a document. For TeXers, the document uses "letter" style.
If you do not care about how to make content with any mathematical symbols, now stop reading. If text input can not satisfy you, just go continuously. The philosophy for TeXmacs to manipulate the contents is very similar to LaTeX does ( but not equal to). Content inputs are divided into three types: text, math and display modes.
Math content, i.e. mathematical symbols together with text content in one line. Then:
The symbols are just like these of usages in TeX. For example: \backslash produces \.
Display Math content, i.e. independent line or lines for Mathematical symbols.
Now, let us show some examples:
Let f be defined on the closed interval [a,b], and let Δ be a partition of [a,b] given that
where Δxi is the width of the ith subinterval. If ci is any point in the ith subinterval, then the sum
n |
i = 1 |
is called the Riemann sum of f for the partition of Δ.
The parts in blue color are in math mode (press US dollar sign and then [→] back to the text mode again) and the parts in red are in display Math mode ( press [∑mr] → [Equation] and move cursor by mouse into next line back to the text mode). The messages shown at the bottom line of TeXmacs may help you at which mode you are and what you have done.
lim‖Δ‖
→0∑
|
(1) |
exists where ‖Δ‖ = below (max, 1⩽i⩽n)|xi - xi - 1| then f is integrable on [a,b] and the limit is denoted by
lim‖Δ‖
→0∑
|
(2) |
The limit is call the definite integral.
The number of equation is produced by [Mathematics] →[Number equation] in display Math mode.
In these two examples, just type as you do in TeX environment, for example ∧ means upper script input and - means lower script input, but not all same.
In Math or display Math mode, we can adjust the script by:
Input symbols under or above other symbols in display math mode, as above adding script space ahead,
below (∫∫, S)B⋅N d S = 4πq | (3) |
After working, choose [File] →[Save] and give a filename, for example filename.tm. This will create a file named as filename.tm in your home directory. If you work on Knoppix Linux, everything will be disappeared after turning off the power since it works on RAM. You had better to use the following command to backup worksheet:
> mcopy filename.tm a:
Now you can turn off the system. Then you can fire up your TeXmacs and enjoy!
Not only the powerful ability of publishing text and math documents, CAS applications can be executed within session of TeXmacs, solving problems and making graphs. The computation ability of CAS will be introduced later and how-to making graphs will be introduced first. Some CAS sessions allow to produce in-line postscript graph in worksheets, i.e. Gnuplot, Octave, but some are not, for example Maxima. For the latter case, users have to embed the result graphs into the worksheet.
The answer is very simple: calculation, including symbolic calculation, for example Maxima and Yacas, numerical calculation, for example Octave, and plotting utility.
Here, we will give a brief introduction for CAS working within TeXmacs.
Licensed under GNU Library General Public License
Contains Enhancements by W. Schelter
Maxima 5.9.0rc3 http://maxima.sourceforge.net
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(C1) |
f(x):=x^3+sin(x)
|
(C2) |
f(%pi)
|
(C3) |
h(x):=block([u:x,w], if (u>0) then w:sin(x) else
w:-sin(x), u+w)
|
(C4) |
h(1)
|
(C5) |
h(-2.0)
|
(C6) |
integrate(x*((x-1)/(x+1))**(1/2),x);
|
log (sqrt (
|
||
8 |
log (sqrt (
|
||
8 |
3 (
|
||||||
-
|
(C7) |
diff(d6,x)
|
( -
|
||||||||||||
( -
|
|
||||
16 sqrt (
|
|
||||
16 sqrt (
|
|
||||||||||||||||
-
|
(C8) |
plot2d(x+sin(x),[x,0,%pi]);
|
(C9) |
|
Here, you can directly define functions or use block structure to define complicate function as (C3). Here, h(x) is defined as x + sin(x) if x>0 and as x - sin(x) if x⩽0. Plotting graph is the best way to understand function. Maxima also applies plot functions, polt2d. The graph is produced in another X-terminal but not in the TeXmacs worksheet. Use another KDE applications to produce the graph and embed the graph into the worksheet by:
Make graph from CAS and save the screen-shot or store it directly into storage. For
Open [Text] →[Session] →[shell], execute the following octave code to make graph:
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 John W. Eaton.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or
FITNESS FOR A PARTICULAR PURPOSE.
Report bugs to <bug-octave@bevo.che.wisc.edu>.
octave> |
t_total=1;
|
octave> |
t_step=500;
|
octave> |
dim=3;
|
octave> |
init_po=[0,0,0];
|
octave> |
increment=sqrt(t_total/t_step)*randn(t_step,dim);
|
octave> |
po=[init_po;increment]; b(1,:)=zeros(1,dim);
|
octave> |
gset parametric;
|
octave> |
gset xrange [-2:2];
|
octave> |
gset yrange [-2:2];
|
octave> |
gset zrange [-2:2];
|
octave> |
for i=2:t_step b(i,:)=po(i,:)+b(i-1,:); endfor
|
octave> |
gset set term postscript enhanced color eps;
|
octave> |
gset xtics 1;gset ytics 1; gset ztics 1;
|
octave> |
gset output
'/home/cchuang/texmacs/brownian.eps';
|
octave> |
gsplot b title "3D Brownian Motion";
|
octave> |
|
After executing the code, brownian.eps is created. Terminate the session and back to the TeXmacs environment. Now choose [Insert] →[Image] → [Insert image] to embed the result graph as follows:
Octave can use the gnuplot syntax to generate graph, but cannot interpreter the resulted PostScript code. Theirfore output the graph and embed it back.
If the effect is not good-looking enough, you can consider another application session, Gnuplot. Gnuplot is more flexible since it applies many utility functions to manipulate graph, including the off-line modification. For example, press [Text] →[Sessions] →[Gnuplot] enters the session. Some simple examples as follows:
GNUplot] |
plot [-pi/2:pi/2][-2:2] x+sin(x)
|
GNUplot] |
set noclip ~set yrange[-30:10] ~plot
x*(abs((x-4)/(x+4)))**(1./2.)
|
GNUplot] |
|
GNUplot] |
set key left ~set xlabel 'x:[cm]' ~ plot [-pi/2:pi/2]
x+sin(x)
|
GNUplot] |
set xlabel 'x:[cm]' ~ plot sin(x)
|
GNUplot] |
set pm3d hidden 100 ~set style line 100 lt 3
~set nosurface ~set size 0.7,1 ~set view
80,180,1,1 ~set noborder ~set noxtics ~set
noytics ~set noztics ~set parametric ~set samples 36
~set isosamples 20,36 ~set ticslevel 0 ~set nocolorbox
~set urange [0:pi] ~set vrange
[0:2*pi] ~splot
sin(u)*cos(v),sin(u)*sin(v),cos(u)
|
GNUplot] |
set xrange[-5:5] ~set yrange[-2:2] ~f(x)=x<0?-1:1 ~plot
f(x)
|
GNUplot] |
|
Due to the auto-scaling effect, not all the range of domain of x + sin(x) is shown in the first graph. After given the range of variable of x, we can observe the graph more explicitly. But how about "set xlabel '[x]'" in single line with other plotting command lines? Due to bug interpretation of the interface of gnuplot, tm_gnuplot, gnuplot cannot handle this code with ghostscript. Instead of inputting plot and set option in different lines, input "set options ~ plot ⋯" to add the set option in normal plotting command. Try directly execute the above code to see what about the differences between two statements. Almost CAS's have their plotting philosophy. For example, Octave, the other famous one, not only has its built-in command, plot, but also fully supports the Gnuplot functions, only by adding a pre "g" before the relative plotting commands.
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 John W. Eaton.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or
FITNESS FOR A PARTICULAR PURPOSE.
Report bugs to <bug-octave@bevo.che.wisc.edu>.
octave> |
x=linspace(-10,10,1000);
|
octave> |
y=x+sin(x);
|
octave> |
plot(x,y,";Function y=x+sin(x);");
|
octave> |
gset term postscript enhanced eps color;
|
octave> |
gset output "demo.eps"
|
octave> |
plot(x,y,";Function y=x+sin(x);")
|
octave> |
|
In the octave generic terminal, the graph will not appear instead of demo.eps being created. By the way, note that its syntax is similar to Matlab but not similar to Maple.
Maxima applies many functions for mathematical calculation, for example, it can be also used to solve the algebra equations:
Licensed under GNU Library General Public License
Contains Enhancements by W. Schelter
Maxima 5.9.0rc3 http://maxima.sourceforge.net
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(C1) |
linsolve([a*x+b*y=m,c*x+d*y=n],[x,y]);
|
d m - b n |
b C - a d |
C m - a n |
b C - a d |
(C8) |
solve(x^3-x=0,x);
|
(C9) |
diff((x^2+a)^(1/2),x);
|
x |
sqrt (x2 + a) |
(C10) |
integrate((x^2+a)^(1/2),x);
|
Is a positive or negative? |
positive
|
a ASINH(
|
||
2 |
x sqrt (x2 + a) |
2 |
(C11) |
integrate((x^2+a)^(1/2),x,0,1);
|
Is a positive or negative? |
negative
|
a log (2 sqrt (a + 1) + 2) + sqrt (a + 1) |
2 |
log (2 sqrt (a)) a |
2 |
(C12) |
limit((x^2+a)^(1/2),x,0);
|
(C13) |
|
The symbolic calculation of Maxima has shown above, including solving equations, evaluating limit, differentiation and integration. In the examples of integration, maxima will ask the user more conditions if necessarily.
Now let us introduce Yacas (yes, another CAS). The following is mini demo:
yacas] |
Solve(x^3+b+1==0,x);
|
yacas] |
D(x) (x^2+a)^(1/2);
|
(x2 +
a)
|
||
2 |
yacas] |
Limit(x,0) (1-Cos(x))/x^2;
|
1 |
2 |
yacas] |
Integrate(x,0,pi) x+Sin(x);
|
π2 |
2 |
yacas] |
f(x):= x+sin(x);
|
yacas] |
GnuPlot(-Pi/2,Pi/2,80,f(x));
|
π |
2 |
π |
2 |
yacas] |
|
The last command of plotting will not have any correspondence here.
Exercise 1. Plot the graphs of the following
functions: a) x2 + 3x - 2 b)
c) sqrt (s2 + 1)
x2 + 1
x4 + x + 1
d)
e) x3 +
sin(πx/2) - 1
1 - x2
f) (x + 1)1/3
3
x2
Exercise 2. Plot the graph of the function:
(x + 1)2 if x> - 1, |
x + 1 otherwise |
Exercise 3. Solve 3x + 4y = 5, 9x + 10y = 11 for x,y.
Exercise 4. Differentiate the functions in Exercise 1.
Which application with plotting ability is excellent? This answer will be different for different persons. From my view, Maxima or Gnuplot is better one if the solutions of functions are in explicit form. But if the solution are in implicit form, consider the tools with numerical utility, for example Octave.
|
= | - 10(x1(t) - x2(t)) | ||||
|
= | 28x1(t) - x2(t) - x1(t)x3(t) | ||||
|
= |
|
||||
Initial condition: | x1(0) = 2, x2(0) = 5, x3(0) = 10 |
Solve this initial value problem by Octave:
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 John W. Eaton.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or
FITNESS FOR A PARTICULAR PURPOSE.
Report bugs to <bug-octave@bevo.che.wisc.edu>.
octave> |
x0=[2;5;10];
|
octave> |
t = linspace (0,10,800);
|
octave> |
function dx = butter (x ,t)
dx(1) = -10.0*(x(1)-x(2));
dx(2) =
28.0*x(1)-x(2)-x(1)*x(3);
dx(3) = 8.0/3.0*( x(1)*x(2) -x(3) );
end;
|
octave> |
y=lsode("butter",x0,t);
|
octave> |
gset parametric;
|
octave> |
plot(y(:,1),y(:,3))
|
octave> |
plot(y(:,2),y(:,3))
|
octave> |
plot(y(:,1),y(:,2))
|
octave> |
gset set term postscript enhanced color eps;
|
octave> |
gset out "/home/cchuang/texmacs/butterfly.eps";
|
octave> |
gset xtics 10;gset ytics 10; gset ztics 10;
|
octave> |
gsplot y title "Butterfly Effect"
|
octave> |
|
At the last part of Octave code, we want to save the 3D trajectory as butterfly.eps. Then we can embed this EPS file:
Certainly, we can also save the data of y and plot with Gnuplot.
Before the end of this topic, don't forget to save the result, [File]→[Saved as]. You can choose the default file-extension, tm, then all the data will be stored in XML-like format. If you want to output the data, press "printer" or export as postscript file since the postscript format is full supported in any Linux systems and this format is the default output format in Linux box.
Just as mentioned before, gnuplot is a very professional software for maintaining scientific data. Here, we collect some interesting plots:
GNUplot] |
f(x,y)=x**6+3*y**2*x**4+(3*y**4-4*y**2)*x**2+y**6
~set pm3d hidden 100 ~set style line 100 lt 6
~set nokey ~set xrange[-1:1] ~set
yrange[-1:1] ~set isosamples 30,30
~set hidden3d ~set contour ~set cntrparam levels discrete
0.05,0,-0.05,-0.5 ~set size 0.7,1 ~splot -f(x,y) w dots
lt 2
|
GNUplot] |
set pm3d at s ~set palette rgb 3,3,3 ~set nocolorbox
~set parametric ~set nokey ~set noztics
~set urange[-5:5] ~set
vrange[0:10] ~set yrange[0:10] ~set zrange[0:1]
~set isosamples 100,100 ~set view 0,0,1.5,1
~set multiplot ~set size 1,1 ~set
origin 0,0 ~set nosurface ~splot u, v,
(v< u**2)? 1:0.8 ~set size 1,1
~set origin ~set surface
~splot u, u**2, 1 with
lines lt 1 lw 3
~unset multiplot
|
GNUplot] |
set pm3d ~set palette rgbform 9,8,9 ~set parametric ~set
hidden3d ~set urange [0:2*pi] ~set vrange [-pi:pi] ~set
isosamples 24,16 ~set size 0.8,1 ~set view
60,20,1,1 ~set ticslevel 0
~x1(u,v)=cos(u)+.5*cos(u)*cos(v)
~y1(u,v)=sin(u)+.5*sin(u)*cos(v) ~z1(u,v)=.5*sin(v)
~x2(u,v)=1+cos(u)+.5*cos(u)*cos(v)
~y2(u,v)=.5*sin(v) ~z2(u,v)=sin(u)+.5*sin(u)*cos(v)
~splot x1(u,v),
y1(u,v), z1(u,v) lt 3, x2(u,v), y2(u,v), z2(u,v) lt 5
|
GNUplot] |
~set pm3d at s solid ~set palette rgb -7,-15,-6 ~set
nocolorbox ~set ticslevel 0 ~set nosurface ~set
noztics ~set hidden3d ~set isosamples
70,70
~complex(x,y)=x*{1,0}+y*{0,1}
~mandel(x,y,z,n) = (abs(z)>2.0 ||
n>1000)?log(n):mandel(x,y,z*z+complex(x,y),n+1)
~a=-0.37 ~b=-0.612
~set multiplot
~set origin
0,0 ~set size 0.5,0.7
~splot [-0.5:0.5][-0.5:0.5]
mandel(a,b,complex(x,y),0) ~set
origin 0.35,-0.15 ~set size 0.7,1.05 ~set view 0,0,,,
~splot [-0.5:0.5][-0.5:0.5]
mandel(a,b,complex(x,y),0) ~set
nomultiplot
|
GNUplot] |
set pm3d ~set pal rgb 15,7,5 ~set nocolorbox
~set noxtics ~set noytics~ set noztics
~Order=13 ~Range=2**Order ~br=0.4616
~bi=0.4616 ~cr=0.6200 ~ci=-0.197~ ~set parametric
~Fx(x,y,n,c)= c>0? n%2==0 ? Fx(br*x+bi*y,
bi*x-br*y, n/2, c-1): Fx(cr*x-ci*y-cr+1,
ci*x+cr*y-ci,n/2,c-1) : x
~Fy(x,y,n,c)= c>0? n%2==0 ?
Fy(br*x+bi*y, bi*x-br*y, n/2, c-1): Fy(cr*x-ci*y-cr+1,
ci*x+cr*y-ci,n/2,c-1) : y
~set samples 2 ~set isosamples Range,2 ~set
urange[1:Range] ~set border 0 ~set
view 0,0,1.8,
~set label "b=0.4616+0.4616i, c=0.62-0.197i"
at 0.1,-0.02 ~splot
Fx(0,0,int(u),Order), Fy(0,0,int(u),Order), int(u)%64
notitle w dots lt pal
|
GNUplot] |
~set pm3d at s solid ~set palette rgb 7,0,0 ~set
nocolorbox ~set parametric ~set border 0 ~set
hidden3d ~set nokey ~set noxtics ~set noytics
~set noztics ~set isosamples 30,18 ~set view ,,1.2,1
~set ticslevel 0 ~set urange[0:pi] ~set
vrange[-pi:pi] ~splot
sin(u)*cos(v),sin(u)*sin(v),cos(u)+sin(u) lt 6
|
GNUplot] |
~set pm3d at s solid ~set palette rgb 7,8,3 ~set
nocolorbox ~set parametric ~set border 0 ~set
hidden3d; set nokey ~set noxtics ~set noytics
~set noztics ~set ticslevel 0 ~set isosamples 48,48
~set view 70,330,1.5,1 ~set urange[0:pi] ~set
vrange[-pi:pi] ~r(u,v,a) =
abs(sin(u*2)*cos(v*2))**a
~x(u,v,a) = r(u,v,a)*sin(u)*cos(v)
~y(u,v,a) = r(u,v,a)*sin(u)*sin(v)
~z(u,v,a) =
r(u,v,a)*cos(u)
~a=0.7;
~splot
x(u,v,a),y(u,v,a),z(u,v,a) w lines 6
|
GNUplot] |
|
From user's view, plenty of packages can be used is a good news. But in practical, users are not necessary to learn all the syntaxes of different tools. Just focus on how to solve the problems. For example, there are maxima, octave and Scilab etc. many CAS softwares famous for their facilities to solve mathematical problems. Maxima and Yacas are known due to symbolic computing ability but only supports few basic function, and others are famous for their portable syntaxes (like propriety software, Matlab or Maple) and many, many functions but without symbolic ability. With the help of TeXmacs, we can solve right problems by using suitable tools. We will introduce other softwares in the latter chapters.
Among the tools packages in Linux we introduce in TeXmacs environment here, some experiences have to be kept in mind:
Output format: Postscript format is the best choice as above mentioned. For the Windows user and not heard about this format, HTML format may be the suitable one. But for mathematical document, it is may be a bad news that directly output the HTML from TeXmacs is generally non-satisfied. If you want to generate HTML files, LaTeX2html maybe have some help. Consider to export LaTeX format from TeXmacs and use the following latex2html command to translate TeX file into HTML and picture files:
> latex2html -nonavigation -split 0 filename.tex
if you want only one HTML file with picture files without navigation icons. Suppose that there are plenty of pictures generated by CAS's in your TeXmacs file, some modifications have to be made by your hand. The reason is that no PS Tricks implement yet in latex2html and this is just the TeX package used by TeXmacs to make in-line Postscript graphs. First capture the pictures by picture capture program, e.g. ksnapshot or GIMP, by CAS's in another xterm and save it as eps format. Then edit the LaTeX file, removing all lines including "cat code ⋯" in presume part and adding the eps graphs as follows :
\document[12pt]{article} \package[dvips]{graphics} ⋯ % remove all the line beginning with "catcode" ⋯ \begin{document} ⋯ \begin{center} \resizebox{150mm}{!}{\includegraphics{picture.eps}} \end{center} ⋯ \end{document}
Mainly, add the graphics package and use \include graphics{} to put the graph. And use above latex2html commands to translate the contents. The directory named by its filename will be created with HTML file, and png files.
Hope this mini introduction help everybody. Any question or comment email:
Resources:
GNUplot] |
plot x**2+3*x-2
|
GNUplot] |
plot (x**2+1)/(x**4+x**2+1)
|
GNUplot] |
plot sqrt(x**2+1)
|
GNUplot] |
set xrange[-5:5] ~set yrange[-5:5] ~set grid ~set xtics 1
~set ytics 1 ~plot (sin(x*pi/2)-1)/(x**2-1)
|
GNUplot] |
set xrange[-5:5] ~set yrange[-100:100] ~set noclip ~plot
x**3+3/x**2
|
GNUplot] |
plot (x+1)**(1./3.)
|
GNUplot] |
|
Note that gnuplot is sensible for the type of number, integer or real number. If the square is written as 1/2, quotient of integers, instead of the original 1./2., quotient of real numbers, an error will occur due to the rational power. Turn to the Maxima session:
Licensed under GNU Library General Public License
Contains Enhancements by W. Schelter
Maxima 5.9.0 http://maxima.sourceforge.net
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(C1) |
plot2d((1+x)^(1/3),[x,-5,4]);
|
(C2) |
|
The result is:
GNUplot] |
set key left ~set xrange[-5:5] ~f(x)=x>-1?(x+1)**2:x+1
~plot f(x)
|
GNUplot] |
|