Using CAS sessions in TEXMACS

One important feature of TeXmacs is that users can "execute" external (CAS) within worksheet. Supported CAS’s include: octave gnuplot qcl etc. The detailed menu will be listed in [Insert] [Session] according to exactly CAS’s installat- tions1 in your system. →

1. Octave

When you choose from the [Octave] choice from [Insert] [Session] or from submenu in middle line, octave will be invoked and you can input the octave→ command after the prompt as follows: octave> A=[1 0 0 0;2 2 0 0;-1 0 2 0;0 -1 2 2] octave> A^2 octave> A.^2 octave> eig(A) octave> [U,V]=eig(A) octave> V.^1 octave> U.^1 octave> A’ octave>

1.1. Linear System Equations

The following equation can be solved only by division:

ax = b x = b/a if a  0 ⇒

The method for solving linear system equation is similar as follows:

I

I 1 I Am nXI n 1 = bm 1 Xn 1 = Am− nbm 1 × × × ⇒ × × ×

And octave support the operation for such solution: I

1 I I XI n 1 = Am− nbm 1 Xn 1 = Am n bm 1 × × × ⇒ × × × / Example 1. Solve the linear system of equations:

x + x = 2 − 1 2 2x + 3x = 1 1 2 − This system of equations can be rewritten as:

1 1 x 2 1 = −2 3 x 1   2   −  Now the solution by octave is: octave> A=[-1 1; 2 3];b=[2;-1] octave> A\b octave>

Note the command is A b but neither A/b nor b/A. \

Exercise 1. Solve the following systems of equations:

i. x + 2x + 3x = 2 − 1 2 3 4x1 5x2 + 6x3 = 1 7x − 8x + 9x = 1− 1 − 2 3 ii. 1.1 x + 2.2x + 3.3x = 2.2 − 1 2 3 4.4x1 5.5x2 + 6.6x3 = 1.1 7.7x − 8.8x + 9.9x = 1.1− 1 − 2 3

1.2. LU Decomposition

Another method, UV decomposition, is usually used in large linear systems. Suppose that I AXI = b

This equation can be solved as follows:

I

I I I PAX = LUX LyI = Pb =

⇒ I Iy = L c

⇒ \ I

X = U Iy ⇒ \ where L is a lower triangular matrix and U is an upper triangular matrix. The octave command about this LU decomposition is

[ LUP] = lu( A)

Example 2. Solve the same problem in Example 1 in LU decomposition. And compare the solutions. octave> A=[-1 1; 2 3];b=[2;-1] octave> [L U P]=lu(A) octave> y=L\(P*b) octave> x=U\y octave> x.^1 octave>

Exercise 2. Solve the problems in Exercise 1 by LU decomposition. 1.3. Octave Programming

Not only the fundamental mathematical functions octave supports, programmability is also sup- ported too. octave> A=[1 0 0 0;2 2 0 0;-1 0 2 0;0 -1 2 2] octave> A^2 octave> A.^2 octave> [u,v]=eig(A) octave> Q=[1 0 0 0;-2 2 1 0;1 1 0 0;-4 0 0 -1] octave> P=inv(Q) octave> P*A*Q The first octave program example is to plot graph of mathematical function, y = x + sin x. Unlike general alike , Octave plot such graph piecewisely. In other words, we have to partition the parameter axis into several nonoverlapping subintervals firstly as following:

x = linspace( xinit, xend, number of intervals) − − and plot the curve as: y = function( x) plot( x, y, ′′ ; title; ′′ ) A simple plotting example is given: 1. Partition [10,-10] into 1000 non-overlapping subintervals: octave> x=linspace(-10,10,1000); 2. define the function, y( x) = x + sin x octave> y=x+sin(x); 3. plot octave> plot(x,y,";Function y=x+sin(x);");

10 Function y=x+sin(x) 8 6 4 2 0 -2 -4 -6 -8 -10 -10 -5 0 5 10 octave> z=x+cos(x);hold on octave> plot(x,z,";z=x+cos(x);");

10 Function y=x+sin(x) z=x+cos(x) 5

0

-5

-10

-15 -10 -5 0 5 10 octave> octave> For more detailed explanation, we can use “set options” to modify the defaulted output, such as the tics, title and format etc. In the following example, we will use the octave command: gsplot(3d data) − to plot a 3D curve:

( x( ) , y( t) , z( t)) = ( cos2πt, sin2πt,t)

Actually, the former ( x( t) , y( t)) pair is come from the Euler formulae, famous complex number: e 2πıt = cos2πt + ısin2πt where ı is √ 1 − octave> t=linspace(0,3,200); Define the particle position ( x( t) , y( t) , z( t)) in parametric form octave> x=cos(2*pi*t); octave> y=sin(2*pi*t); octave> z=t; octave> wave = [x’,y’,z’]; octave> grid Plot a parametric graph octave> gset parametric octave> gset ticslevel 0 set up format of the the output and save octave> gset term postscript enhanced eps color octave> gset out "/tmp/wave.eps" Plot the the graph with 3D data octave> gsplot wave octave> The example describe and the result is as follows:

line 1

3 2.5 2 1.5 1 0.5 1 0.6 0.8 0 0.2 0.4 -1-0.8 0 -0.6-0.4-0.2 -0.4-0.2 0 0.2 0.4 -0.8-0.6 0.6 0.8 1 -1

Figure 1. Euler Representation Nowadays, this formulae is very useful to describe how the wireless network works!

Exercise 3. Plot the graph of function, y = sin( x)/x, around x = 0. and gauss what the limit of y at x = 0 is.

1.4. ODE simulations

One of the powers of Octave is modeling and simulations. The following example is to simulate the system of ODEs (Ordinary Differential Equation): dx ( t) 1 = 10( x ( t) x ( t)) dt − 1 − 2 dx ( t) 2 = 28x ( t) x ( t) x ( t) x ( t) dt 1 − 2 − 1 3 dx ( t) 8 3 = ( x ( t) x ( t) x ( t) ) dt 3 1 2 − 3 Initial condition: x1 (0) = 2, x2(0) = 5, x3(0) = 10 and output the resulted in postscript format:

Initial condition: octave> x0=[2;5;10]; octave> t = linspace (0,10,800); The Differential Equations 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; Solve the DE numerically octave> y=lsode("butter",x0,t); octave> gset parametric; octave> gset term postscript enhanced color eps; octave> gset xtics 10;gset ytics 10; gset ztics 10; Output the result in eps format octave> gset out "/tmp/butterfly.eps"; octave> gsplot y title "Butterfly Effect" octave>

At the last part of Octave code, we first save the 3D trajectory as butterfly.eps in /tmp directory. Then we can embed this EPS file into the worksheet as follows:

Butterfly Effect

50 40 30 20 10 0 20 10 -20 0 -10 0 -10 10 20 -20

Figure 2. Butterfly Effect

In the small octave codes, the first part shows the operation about linear algebra, multiplication, inverse and signalization of matrix. The second part shows the graph capacity of Octave, 2D and 3D graphs. 2D graphs can be automatically embedded into the worksheet but 3D graphs are not. You have to save the results somewhere and insert the results. You can download from http://octave.sf.net

Exercise 4. (van der Pol Equation) Consider the following initial value problem:

d2 x dx (1 x2 ) + x = 0 dt2 − − dt x(0) = 0 dx (0) = 1 dt

a) Plot the graph for ( t, x( t)) within 10 unit time.

b) Plot the parametric graph for ( x( t) , x ′( t)) . Hint: Consider the vector, Iy : x( t)

Iy = x ( t)  ′  and transform the original second order ODE of x( t) into first ODE of y( t) :

y ( t) ′ y = 1 ′ y ( t)  2  x ( t) = ′ x ( t)  ′′  y1′ ( t) = y2 ( t) 2 y′ ( t) = (1 y ( t) ) y ( t) y ( t) 2 − 1 2 − 1 Finally, the system of ODE’s becomes

y ( t) y ( t) y = 1′ = 2 ′ y ( t) (1 y ( t) 2 ) y ( t) y ( t) 2′ !  − 1 2 − 1  Exercise 5. Challenge problem. 226

The differential equation for the famous Rutherford’s experiment, emitted α-particle toward Ra88 particle is as followed: 2 2 d x Zα ZAue x 2 = 3 dt 4πε0mα r 2 2 d y Zα ZAue y 2 = 3 dt 4πε0mα r where the velocity of α is v0 = 0.053[ c] . After all, the equations become: d2 x x = 0.0164 dt2 r3 d2 y y = 0.0164 dt2 r3 A simulation is as follows:

Figure 3. Rutherford Scattering Simulation

Derive the equations into first order system ODE’s for Ip ( t) = ( x( t); x ′( t); y( t); y′( t)) . 1.5. ODE Revisited

1.5.1. Newton Scheme

Remember the great Newton’s linear approximation:

f( xi +1 ) f( xi) + f ′( xi 1 ) ∆x ∼ − · where ∆x is the unit length for x partition. Consider the following mechanical problem:

L

θ1

L1 W1 L4 θ2 W2 W L2 3 θ θ3 4 L3 where Li , i = 1 , 2, 3, 4, is the length for each section, Wi , i = 1 , 2, 3, is the weight of the hang ball and θi , 1 , 2, 3, 4 is the angle between the horizontal level and the line section at each ball. The governed equations for this system are as follows :

4 Li cos θi L = 0 − i =1 X 4 Li sin θi = 0 i =1 X f( xi) f( xi ) cos θi = 0 ( where i = 1 , 2, 3) − +1 +1 f( xi) f( xi ) sin θi Wi = 0 ( where i = 1 , 2, 3) − +1 +1 −

In this octave example, the values for the weight ( W2, 1 6 W2 6 3) and the total length, ( L, 1 6 L 6 4) have to be input by user. the result for W2 = 2 and L = 4 is shown as follows:

L1=L2=L3=1, L=4 0

-0.5

-1

-1.5

-2

-2.5

-3

-3.5

-4 0 0.5 1 1.5 2 2.5 3 3.5 4

Figure 4. W2 = 2 and L = 4 case

The octave code is as follows:

Shell session inside TeXmacs shell] cat mass.oct e=1e-8; d1=1;ds=1; L1=1;L2=1;L3=1;L4=4;L=4; W1=1;W2=1;W3=1; W2=input("W2 = "); #L=input("L = "); c1=(L^2+(L1+L2+L3)^2-L4^2)/(2*L*(L1+L2+L3)); c2=c1;c3=c1; c4=(L^2+L4^2-(L1+L2+L3)^2)/(2*L*L4); W=[W1;W2;W3;0]; a=0.1; b=0.01; while( abs(d1)>e || abs(d2)>e || abs(ds)>e || abs(dc)>e ) s1=sqrt(1-c1^2);s2=sqrt(1-c2^2); s3=sqrt(1-c3^2);s4=-sqrt(1-c4^2); A=[s1,-s2,0,0;0,s2,-s3,0;0,0,s3,-s4;0,0,c3,-c4]; X=A\W; t1=X(1);t2=X(2);t3=X(3);t4=X(4); d1 = t1*c1-t2*c2; d2 = t2*c2-t3*c3; dc = L1*c1+L2*c2+L3*c3+L4*c4-L; ds = L1*s1+L2*s2+L3*s3+L4*s4; z1 = c1 - a*d1/t1; z2 = c2 - a*d2/t2; z3 = c3 - b*dc/L4; s4 = s4 - b*ds/L4; z4 = sqrt(1-s4^2); c1=z1;c2=z2;c3=z3;c4=z4; if c3 >=1 c3=1; endif endwhile s1=sqrt(1-c1^2);s2=sqrt(1-c2^2); s3=sqrt(1-c3^2);s4=-sqrt(1-c4^2); r1=real([L1*c1, -L1*s1]); r2=r1+real([L2*c2, -L2*s2]); r3=r2+real([L3*c3, -L3*s3]); r=[0 0; r1; r2; r3; L 0]; axis([0,4,-4,0], "equal"); gset pointsize 5 label1=sprintf("W_1=%.1f", W1); label2=sprintf("W_2=%.1f", W2); label3=sprintf("W_3=%.1f", W3); lt1=sprintf("T_1=%f", t1); lc1=sprintf("cos{/Symbol q}_1=%f", c1); lt2=sprintf("T_2=%f", t2); lc2=sprintf("cos{/Symbol q}_2=%f", c2); lt3=sprintf("T_3=%f", t3); lc3=sprintf("cos{/Symbol q}_3=%f", c3); lt4=sprintf("T_4=%f", t4); lc4=sprintf("cos{/Symbol q}_4=%f", c4); title("{ L_1=L_2=L_3=1, L=4}"); plot(r(:,1), r(:,2), "-2;;"); plot(r(2:4,1), r(2:4,2), "@17;;"); pause gset term postscript enhanced color eps "Times" 20 gset out "mass3.eps" replot shell]

1.5.2. lsode: charged particle travelling

Consider a charged particle travels within a electromagnetic field with

BI = (0, 0, Bz)

EI = (0, Ey , 0)

The governed equation is :

dvI

I I

m = q E + qI v + B dt

The octave code for the case with m = 1 , q = 1 , Ey = 1.5 and Bz = 3 is as follows: shell] cat emmision.oct

x2 (%o3) cos ( x) 2 − (%i4) shell]

Then the trajectory of the particle is as like:

Ey=1.5, Bz=3.0

10 8 6 4

2 4 0 2 -4 0 -2 y 0 -2 2 x 4 -4

Figure 5. Bz = 3 and Ey = 1.5

ODE’s is an important tool for studying physics. But ODE’s can not be usually solved in exact form. Numeric scheme is a powerful method to simulate the solution of ODE. Another method to describe the phenomena of solution is the quantitative method. Back to the van der Pol example in the last section: d2 x dx (1 x2 ) + x = 0 dt2 − − dt

This is a equation to describe the self auto-vibrating motion. As x2 < 1 , i.e. the coefficient of the second term, dx/dt, the change of amplitude of oscillation will be increasing if dx/dt is negative, i.e. velocity is negative. In the contrary, as x2 > 1 , the change of amplitude will be decreasing if dx/dt is positive, i.e. velocity is positive. Here is the octave code about this: octave> function dx = vanderpol(x,t) dx(1)=x(2); dx(2)= (1-x(1)^2)*x(2)-x(1); end octave> N=201; octave> X0=[0.0;1.0]; octave> t=linspace(0,10,N); octave> xlabel("x");ylabel("v"); octave> title("van der Pol") octave> for i=0:3 hold on; x=lsode("vanderpol",X0,t); plot(x(:,1),x(:,2)); X0=[x(N,1); x(N,2)]; endfor

van der Pol 3 line 1 2 line 2 line 3 1 line 4

v 0 -1 -2 -3 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 x octave>

If there is extra external force under consideration, the model might become:

d2x dx (1 x2) + x = f cos ωt dt2 − − dt

Exercise 6. Plot the graph, ( t, x( t)) , with f = 1.0, ω = 2π and the initial condition:

dx x(0) = 0, (0) = 2, 0 dt − within 30 6 t 6 60.

1.5.3. Steep Condition Case: Runge-Kutta Method lsode scheme is suited for the cases that Newton stability conditions holds. But in many instable cases, the truncated error will becomes rapidly. In such cases, lsode will not be used. Octave also supports many useful extensible codes, contributed by its users, and can be downloaded from official site. All the codes are packed as a compressed file, called octave-forge.tgz. rk4fixed, Runge-Kutta with fixed steps, scheme is come from the octave-forge and it suits for the instable ODE. Here, the codes for last example, Rutherford Scattering experiment, is as follows:

Shell session inside TeXmacs shell] cat scattering.m function dx = em(x,t) global q m Ey Bz dx(1) = x(2); dx(3) = x(4); dx(5) = x(6); dx(2) = q*x(4)*Bz/m; dx(4) = (q*Ey - q*x(2)*Bz)/m; dx(6) = 0; endfunction

global q m Ey Bz m=1.0; q=1.0; Ey=1.5; Bz=3.0;

t=linspace(0,20,201); X0=[0, -1, 0, 0, 0, 0.5]; r=lsode("em", X0, t); axis([-5 5 -5 5 0 10],"square"); xlabel("x"); ylabel("y"); Title=sprintf("{E_y=%.1f, B_z=%.1f}",\ Ey, Bz); title(Title); #text(0.05,0.95,"{/Courier=28 01ks000}","Units","screen")

rr=[r zeros(201,1)]; gset parametric gset ticslevel 0 gset grid; gset nokey; gsplot rr using 1:3:5, rr using 1:3:7 ; pause % for creating PS figure gset term postscript enhanced color eps "Helvetica" 20 gset out "emdrift.eps" shell] octave scattering.m shell]

First put scattering.m and rk4fixed.m in the same directory. Then use the last command to execute the octave code. Et voila!

Rutherford Scattering of 5.3 MeV He

Figure 6. Zoom-in and Zoom-out View for Scattering

Exercise 7. Complete the last example such that the result will be embedded within the document. 2. Maxima

Maxima is another CAS famous for its symbolic calculation. And what is so-called that software owns functionality of symbolic calculation? Let us explain in brief: the main difference between traditional computation and symbolic calculation is that the former calculates math “numerically” but the latter can calculate math theoretically. For instances, let f( x) be the sine function, i.e. f( x) = sin( x) . The symbolic calculation allows users to apply any operation over f( x) , addition, abstraction and differentiation etc. But the traditional computation only allows users to evaluate the function at some specified value, e,g, f( π/2) = 1 . Installation You can download the newest source or binary files from http://maxima.sf.net At its official site, you can find that almost OS systems are supported, including , OSX, Unix and MS-Windows. If you are installed directed from source, install guile and gcl at first. If any error occurs due to the scheme compile error, just press return to continue the installation and repeat the make procedure. The following example shows that some symbolic functionalities of Maxima for function f( x) = + sin( x) , including differentiation, integration and plotting:

Maxima is another CAS famous for its symbolic calculation. You can download the newest source or binary files from http://maxima.sf.net In installation procedure from source, if any error occurs due to the scheme compile error, just press return to continue the installation and repeat the make procedure. The following are some simple examples:

Maxima 5.9.2 http://maxima.sourceforge.net Using Lisp GNU (GCL) GCL 2.6.6 (aka GCL) 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. (%i1) f(x):=x+sin(x)

(%o1) f( x) : = x + sin ( x) (%i2) diff(f(x),x)

(%o2) cos ( x) + 1 (%i3) integrate(f(x),x)

x2 (%o3) cos ( x) 2 − (%i4) integrate(f(x),x,0,%pi)

π2 + 4 (%o4) 2 (%i5) plot2d(f(x),[x,-4,4]) (%o5) (%i6)

The result graph of (C4) will be shown in another pop-up window generated by maxima but not embed into worksheet. We can use [Insert] [Image] to add the result graph as: →

Figure 7.

As the maxima was installed, some introduction and demos will be included in the directory: $prefix/share/maxima/version/. The following will focus on the topic of differentiable equations. The command is as follows:

ode2( D.E., y, x)

(%i6) EQ1:’diff(y,x)+y

d (%o1) y + y d x (%i2) ode2(EQ1,y,x)

x (%o2) y =%ce− (%i3) ic1(%o2,x=0,y=2)

x (%o11) y = 2 e− (%i12) EQ2:’diff(y,x,2)+y

d2 (%o4) y + y d x2 (%i5) ode2(EQ2,y,x)

(%o5) y = %k1 sin ( x) + %k2 cos ( x) (%i6) ic2(%o5,x=0,y=1,’diff(y,x)=-1)

(%o9) y = cos ( x) sin ( x) − (%i10) bc2(%o5,x=0,y=1,x=1,y=-1)

( cos ( 1 ) + 1 ) sin ( x) (%o10) y = cos ( x) − sin ( 1 ) (%i11)

Within the maxima session, we also introduction the Initial Condition,

ic1( solution, xval, yval) for the first order D.E. ic2( solution, xval, yval) for thesecond order D.E.

(%i12) ’diff(f(x),x)=’diff(g(x),x)+sin(x);

d d (%o1) f( x) = g( x) + sin ( x) d x d x (%i2) ’diff(g(x),x,2)=’diff(f(x),x)-cos(x);

d2 d (%o2) g( x) = f( x) cos ( x) d x2 d x − (%i3) desolve([%o1,%o2],[f(x),g(x)]);

d d d d (%o3) f( x) = ex g( x) g( x) + f( 0) , g( x) =ex g( x) g( x) + d x − d x d x − d x   x =0  x =0  x =0  x =0 cos ( x) + g( 0) 1 −  (%i4) atvalue(’diff(g(x),x),x=0,a);

(%o4) a (%i5) atvalue(f(x),x=0,1);

(%o5) 1 (%i6) desolve([%o1,%o2],[f(x),g(x)]);

(%o6) [ f( x) = a ex a + 1 , g( x) = cos ( x) + a ex a + g( 0) 1 ] − − − (%i7)

This example, here, is come from the Maxima doc. It describes how to solve a system of D.E.

Exercise 8. (Prey and Predator) Considers two populations of preys ( p( t)) and predators ( P( t)) , related by the equations:

dp = 2 p 0.01 pP dt − dP = P + 0.01 pP dt − where t is given by years. Solve this equations with the initial conditions p(0) = 300 and P(0) = 150 over the first 100 years. Also plot the graphs for p( t) and P( t) .

Exercise 9. The motion of an ideal pendulum of length l is (see the following figure) governed by the equation:

θ = gl sinθ ′′ − where θ is the angle of the pendulum from the vertical and g = 9.81 m/sec2 .

a) Solve θ = θ( t) in the interval [0, 10] .

2 b) plot θ and θ ′ if l = 0.5m, with initial conditions: θ(0) = 1 radian and θ ′(0) = 0 rad/sec .

l θ

Sol: • (%i4) g:9.81

(%o1) 9.810000000000001 (%i2) l:0.5

(%o2) 0.5 (%i3) EQ:’diff(y,x,2)+g*l*sin(y)

d2 (%o3) y + 4.905 sin ( y) d x2 (%i4) ode2(EQ,y,x)

‘rat’ replaced 4.905 by 981//200 = 4.905 10 1 d y 10 1 d y cos ( y) %k1 cos ( y) %k1 (%o4) − = x + %k2, − = x + %k2  − R p 3 √109 R p 3 √109    (%i5) Example 3. (Logistical Model) Assume that all individuals are equally susceptible and certain an infectious disease is introduced to the population by one infective. Suppose that there are individ- uals and the the number of infectives at any given time t is denoted by x( t) . Since the disease is spread through contacts between infectives and noninfectives, the rate at which individuals become infected depends on both the number of infectives x( t) and the number of the noninfectives N x( t) t dx( t) − at any given time . Then the rate of infection, represented by dt , is assumed proportional to the product of x( t) and N x ( t) : − dx( t) = kx( t)( N x( t)) dt − where k is a constant. Sol: In general, the solution for the epidemic model

dX( t) = kX( t)( N X( t)) dt − is in the form N X( t) = Nkt 1 + Be − where B is a positive constant and its graph is like "S-shaped". The case with B = 19,N = 2000, N0 = 100 and Nk = 0.33106 is shown as the follows:

This is a TeXmacs interface for GNUplot. GNUplot] plot [0:25] [0:2050] 100,1000,2000,2000/(1+19*exp(-0.33106*x))

2000 100 1000 2000 2000/(1+19*exp(-0.33106*x))

1500

1000

500

0 0 5 10 15 20 25

GNUplot]

Problem 1. As above, plot the graphs if a) N0 = 1000 and b) N0 = 1500 Sol: Hint: Solve the relation between N and B first: • 0 From the previous result, we have

N N = 0 1 + B N

 B = 1 N0 −

a) N0 = 1000 implies B = 1 . Thus the solution for X( t) is:

2000 X( t) = 0.33106 t 1 + e −

b) N0 = 1600 implies B = 1/3. Thus the solution for X( t) is:

2000 X( t) = 1 + 1 e 0.33106 t 3 −

GNUplot] plot [0:25] [0:2050] 1000,2000,2000/(1+19*exp(-0.33106*x)),2000/(1+exp(- 0.33106*x)),2000/(1+exp(-0.33106*x)/3)

2000 1000 2000 2000/(1+19*exp(-0.33106*x)) 2000/(1+exp(-0.33106*x)) 2000/(1+exp(-0.33106*x)/3)

1500

1000

500

0 0 5 10 15 20 25

GNUplot]

Exercise:

Solve the following differential equations (if solvable) and plot the curves of solution if (*)by Maxima:

1. (*) y ′′ 3 y ′ + 2 y = 0 with a) y(0) = 2, y ′(0) = 1 b) y(0) = 1 , y(1) = e. − Sol: •

Maxima 5.9.2 http://maxima.sourceforge.net Using Lisp GNU Common Lisp (GCL) GCL 2.6.6 (aka GCL) 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. (%i1) EQ1:’diff(y,x,2)-3*’diff(y,x)+2*y=0 d2 d (%o1) y 3 y + 2 y = 0 d x2 − d x   (%i2) ode2(EQ1,y,x)

(%o2) y = %k1 e2 x +%k2ex (%i3) ic2(%o2,x=0,y=2,’diff(y,x)=1)

(%o3) y = 3 ex e2 x − (%i4) ic2(%o2,x=0,y=1,’diff(y,x)=%e)

(%o9) y = ( e 1 ) e2 x + ( 2 e) ex − − (%i10)

The solution graphs are displayed as follows:

GNUplot] plot [0:5] [0:50] 3*(exp(1))**x-(exp(1))**2*x,(exp(1)- 1)*(exp(1))**2*x+(2-exp(1))*(exp(1))**x

50 3*(exp(1))**x-(exp(1))**2*x (exp(1)-1)*(exp(1))**2*x+(2-exp(1))*(exp(1))**x

40

30

20

10

0 0 1 2 3 4 5

GNUplot]

2. xy ′ = 1 Sol: • GCL (GNU Common Lisp) Version(2.4.4) Thu Aug 7 07:33:19 CEST 2003 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) ODE2(x*’diff(y,x)-1=0,y,x) (D5) y = log x + %C (C6)

x 3. y y ′ = e Sol: • (%i7) EQ2:y(x)*’diff(y(x),x)=%e^x

d (%o1) y( x) y( x) = ex d x   (%i2) ode2(EQ2,y(x),x)

y( x) 2 (%o2) = ex + %c 2 (%i3) solve(%o2,y(x))

(%o3) y( x) = √2 √ex + %c, y( x) =√ 2 √ex + %c − h i (%i4)

2 4. y y ′ = ln x Sol: • (%i15) EQ3:y(x)^2*’diff(y(x),x)=log(x)

d (%o1) y( x) 2 y( x) = log ( x) d x   (%i2) ode2(EQ3,y(x),x)

y( x) 3 (%o2) = x log ( x) x + %c 3 − (%i3) solve(%o2,y(x))

5 1 1 3 6 i 3 3 ( x log ( x) x + %c) 3 (%o3) y( x) = − − , y( x) =    2 − 5 1 1 6  3 3 3 i + 3 ( x log ( x) x + %c) 1 1 − , y( x) = 3 3 ( x log ( x) x + %c) 3   2 −   (%i4)

5. ( x + 1) y ′ = y Sol: • (%i4) EQ4:(x+1)*’diff(y(x),x)=y(x)

d (%o1) ( x + 1 ) y( x) = y( x) d x   (%i2) ode2(EQ4,y(x),x)

(%o2) y( x) = %c ( x + 1 ) (%i3)

6. (*) y ′ + 2xy = 0 with y(0) = √π/2 Sol: • (%i3) EQ5:’diff(y(x),x)+2*x*y(x)=0

d (%o1) y( x) + 2 x y( x) = 0 d x (%i2) ode2(EQ5,y(x),x)

x 2 (%o2) y( x) =%ce− (%i3) ic1(%o2,x=0,y(0)=sqrt(%pi)/2)

2 √π e x (%o5) y( x) = − 2 (%i6)

7. y ′′ + y ′ 6 y = 0 − Sol: • (%i6) EQ6:’diff(y,x,2)+’diff(y,x)-6*y

d2 d (%o1) y + y 6 y d x2 d x − (%i2) ode2(EQ6,y,x)

2 x 3 x (%o2) y = %k1 e +%k2e− (%i3)

8. y ′′ 4y ′ + 4y = sin( x) with y(0) = 1 and y ′(0) = 2. − Sol: • (%i3) EQ8:’diff(y,x,2)-4*’diff(y,x)+4*y=sin(x)

d2 d (%o1) y 4 y + 4 y = sin ( x) d x2 − d x   (%i2) ode2(EQ8,y,x)

3 sin ( x) + 4 cos ( x) (%o2) y = + ( %k2 x + %k1 ) e2 x 25 (%i3) ic2(%o2,x=0,y=1, ’diff(y(x),x)=2)

3 sin ( x) + 4 cos ( x) x 21 (%o3) y = + + e2 x 25 5 25   (%i4) 600 ((3*sin (x)+4*cos (x))/25)+((x/5)+(21/25))*(exp(1))**2*x

500

400

300

200

100

0 0 5 10 15 20

We can also solve ODE by laplace transform. Suppose that f = f( x) , x > 0, define the Laplace transform of f( x) as follows: ∞ xs Lf( s) = e − f( x) dx Z0 After transforming the ODE and initial conditions (or boundary conditions), find out the Lf( t) and take inverse Laplace transform over it. Then ODE is been solved! Consider the last exercise again:

d2 d 1. ODE: 2 y( x) 4 y( x) + 4 y( x) = sin x d x − d x I.C.’s: y(0) = 1 and y ′(0) = 2 (%i17) EQ:’diff(y(x),x,2)-4*’diff(y(x),x)+4*y(x)=sin(x)

d2 d (%o14) y( x) 4 y( x) + 4 y( x) = sin ( x) d x2 − d x   (%i15) atvalue(y(x), x=0, 1);

(%o15) 1 (%i16) atvalue(’diff(y(x), x), x= 0, 2);

(%o16) 2 2. Laplace Transform over the ODE (%i17) lap_ode:laplace(EQ,x,s)

1 (%o17) 4 ( s ( y( x) ,x,s) 1 ) + s 2 ( y( x) ,x,s) + 4 ( y( x) ,x,s) s 2 = − L − L L − − s 2 + 1 3. Solve ( y( x) ,x,s ) L (%i18) sol:solve(%, ’laplace(y(x), x, s))

s 3 2 s 2 + s 1 (%o18) ( y( x) ,x,s) = − − L s 4 4 s 3 + 5 s 2 4 s + 4  − −  4. Inverse Laplace transform: where the maxima commands is described as followed: a) lambda ([x1 , , xm], expr1 , , exprn): Defines and returns a lambda expression (that is, an

anonymous function) with arguments x1 , , xm and return value exprn.

b) map (f, expr1 , , exprn) Returns an expression whose leading operator is the same as that

of the expressions expr1 , , exprn but whose subparts are the results of applying f to the corresponding subparts of the expressions. (%i19) sol:map(lambda( [eq], ilt(eq, s, x)),sol)

3 sin ( x) 4 cos ( x) x e2 x 21 e2 x (%o19) y( x) = + + + 25 25 5 25   O.D.E. y ′ + 2xy = 0 with y(0) = √π/2 (%i20) de: ’diff(y(x),x)+2*x*y(x)=0

d (%o9) y( x) + 2 x y( x) = 0 d x (%i10) atvalue(y(x),x=0,sqrt(%pi)/2)

√π (%o10) 2 (%i11) lap_ode:laplace(de,x,s)

d √π (%o11) 2 ( y( x) ,x,s) + s ( y( x) ,x,s) = 0 − d s L L − 2   Somehow, this means that 2L ′( s) + sL( s) √π/2 = 0 with L(0) = √π/2. − − (%i12) lap2:-2*’diff(L(s),s)+s*L(s)-sqrt(%pi)/2=0

d √π (%o16) 2 L( s) + s L( s) = 0 − d s − 2   (%i17) atvalue(L(s),s=0,0)

(%o17) 0 (%i18) ode2(lap2,L(s),s)

s s 2 π erf (%o20) L( s ) = e 4 %c 2 − 4  ! (%i21) sol:ic1(%,s=0,L(0)=1)

s 2 s 2 s π e 4 erf 4 L( 1 ) e 4 (%o21) L( s ) = 2 − − 4 (%i22) sol:map(lambda( [eq], ilt(eq, s, x)),sol)

s 2 s 2 s 2 √π e 4 π e 4 erf 2 (%o15) ilt( L( s) ,s,x) = ilt − ,s,x  4  (%i16) diff(L(s),s)  

d (%o5) L( s) d s (%i6) Both the solutions are just the same. 3. Gnuplot

If the effect is not good-looking enough, you can consider another application, Gnuplot, supported by TEXMACS. Gnuplot is more flexible and more powerful since it applies many utility functions to manipulate graph. Press Text Session and choose Gnuplot to invoke this application session. → Some simple examples as follows:

This is a TeXmacs interface for GNUplot.

GNUplot] plot [-10:10][-10:10] x+sin(x)

10 x+sin(x)

5

0

-5

-10 -10 -5 0 5 10 GNUplot] set noclip ~set yrange[-30:10] ~plot x*(abs((x-4)/(x+4)))**(1./2.)

10 x*(abs((x-4)/(x+4)))**(1./2.)

5

0

-5

-10

-15

-20

-25

-30 -10 -5 0 5 10

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]

Gnuplot supports many fancy features for users to make high-class graphs. If the number of commands is more than one, you have to use ~ to adjacent the commands but not enter return as general in Gnuplot manipulation. You can download from http://gnuplot.sf.net 4. Axiom

Axiom is a general purpose Computer Algebra system. It is useful for research and development of mathematical algorithms. The Axiom Language provides a very high level way to express abstract mathematical concepts that are collected in the Axiom Library which defines over 1,000 strongly- typed mathematical domains and categories. Here, the introduction for Axiom will be focused on the topic about high-level symbolic calculation.

D(x^n,x) → ( n 1 ) n x − (1) Type: Expression Integer

D(x^x,x) → x ( x 1 ) log ( x) x + x x − (2) Type: Expression Integer

integrate(1/(1+x^2)^2,x) → x2 + 1 arctan ( x) + x (3) 2x2 + 2  Type: Union(Expression Integer,...)

integrate(1/(1+x^2),x=0..1) → π (4) 4 Type: Union(f1: OrderedCompletion Expression Integer,...)

integrate(sin(x/2)*cos(x/3),x=0..%pi/2) → 5 3 48cos π + 60cos π 30cos π + 18 − 12 12 − 12 ( 11 )  5   Type: Union(f1: OrderedCompletion Expression Integer,...)

integrate(x^2*exp(-x),x=0..infinity) → 2 ( ) 2 2 e −∞ + 2 ( 30) − ∞ − ∞ −  Type: Union(f1: OrderedCompletion Expression Integer,...)

x:=series ’x → x ( 15) Type: UnivariatePuiseuxSeries(Expression Integer,x,0)

sin(x) → 1 1 1 1 1 x x3 + x5 x7 + x9 x11 + O x12 ( 16) − 6 120 − 5040 362880 − 39916800 Type: UnivariatePuiseuxSeries(Expression  Integer,x,0)

log(1+x) → 1 1 1 1 1 1 1 1 1 1 x x2 + x3 x4 + x5 x6 + x7 x8 + x9 x10 + x11 + O x12 ( 17) − 2 3 − 4 5 − 6 7 − 8 9 − 10 11  Type: UnivariatePuiseuxSeries(Expression Integer,x,0)

y:=atan(x) → 1 1 1 1 1 x x3 + x5 x7 + x9 x11 + O x12 ( 19) − 3 5 − 7 9 − 11 Type: UnivariatePuiseuxSeries(Expression  Integer,x,0)

coefficient(y,13) → 1 ( 21 ) 13 Type: Expression Integer

taylor(log(x),x=1) → 1 1 1 1 1 1 1 ( x 1 ) ( x 1 ) 2 + ( x 1 ) 3 ( x 1 ) 4 + ( x 1 ) 5 ( x 1 ) 6 + ( x 1 ) 7 ( x 1 ) 8 + − − 2 − 3 − − 4 − 5 − − 6 − 7 − − 8 − 1 1 ( x 1 ) 9 ( x 1 ) 10 + O ( x 1 ) 11 (1) 9 − − 10 − −  Type: UnivariateTaylorSeries(Expression Integer,x,1)

taylor(log(x),x=2) → 1 1 1 1 1 1 log ( 2) + ( x 2) ( x 2) 2 + ( x 2) 3 ( x 2) 4 + ( x 2) 5 ( x 2) 6 + 2 − − 8 − 24 − − 64 − 160 − − 384 − 1 1 1 1 ( x 2) 7 ( x 2) 8 + ( x 2) 9 ( x 2) 10 + O ( x 2) 11 (2) 896 − − 2048 − 4608 − − 10240 − − Type: UnivariateTaylorSeries(Expression  Integer,x,2)

y:=operator ’y → y (3) Type: BasicOperator

ODE: y ,, ( x) + 2 y , ( x) 3 y( x) = sin( x) − eq1:=D(y(x),x,2)+2*D(y(x),x)-3*y(x)=sin(x) → y ,, ( x) + 2 y, ( x) 3 y( x) = sin( x) (4) − Type: Equation Expression Integer

sol:=solve(eq1,y,x) →

2sin ( x) cos ( x) x ( 3x) particular = − − , basis = e , e − (5) 10 Type: Union(Record(particular: Expressionh Integer,basii  s: List Expression Integer),...)

sols:=sol.particular → 2sin ( x) cos ( x) − − (6) 10 Type: Expression Integer

solg:=c*sol.basis.1+d*sol.basis.2 → x ( 3x) c e + d e − (7) Type: Expression Integer

solt:=sols+solg → x ( 3x) 2sin ( x) + 10c e + 10d e − cos ( x) − − (8) 10 Type: Expression Integer

D(solt,x,2)+2*D(solt,x)-3*solt → sin ( x) (9) Type: Expression Integer

inisol:=solve(eq1,y,x=0,[1,2]) → x ( 3x) 8sin ( x) + 55e 11 e − 4cos ( x) − − − ( 10) 40 Type: Union(Expression Integer,...)

seriesSolve(eq1,y,x=0,[1,2]) → Compiling function %P with type List UnivariateTaylorSeries( Expression Integer,x,0) -> UnivariateTaylorSeries(Expression Integer,x,0) 1 3 7 17 199 67 601 2707 16237 1 + 2x x2 + x3 x4 + x5 x6 + x7 x8 + x9 x10 + − 2 2 − 8 30 − 720 560 − 13440 181440 − 3628800 O x11 ( 11 )  Type: UnivariateTaylorSeries(Expression Integer,x,0)

taylor(inisol,x=0) → 1 3 7 17 199 67 601 2707 16237 1 + 2x x2 + x3 x4 + x5 x6 + x7 x8 + x9 x10 + − 2 2 − 8 30 − 720 560 − 13440 181440 − 3628800 O x11 ( 12)  Type: UnivariateTaylorSeries(Expression Integer,x,0)

→ Here, there are several examples about symbolic calculation in this demo, including: differentiation, integration, power series, Taylor series and ODE solving ( closed form and solution via power series). As the operator variable was acclaimed, we can not take algebraic operation over the variable directly. If it has to be taken algebraic computation, use “clear properties variable ” to release the acclaim first.

Exercise 10. Solve the following problems by Axiom:

1. y′′ + y = 0 with [ y(0) ,y′(0)] = [1 , 1]

2. x3 y + x2 y 2xy = 2x4 ′′′ ′′ −

3. y′ = y/( x + y lny)

4. y′′′ = sin( y′′) exp( y) + cos( x) with [ y(0) ,y′(0) ,y′′(0)] = [1 , 0, 0] by power series method.

5. Challenge solve the nonlinear first order equations:

2 x ′( t) = 1+( x ′′( t))

y′( t) = x( t) + y( t) I.C. [ x(0) ,y(0)] = [1 , 0] Example 4. (Heat Equation) As well-known, heat equation is a important partial differential equation (PDE) of parabolic type. The method of solving ODE can not be used to solve this PDE. In this example, heat equation can be transformed into ODE and solved by the ODE solver. Heat equation: ∂u( x, t) ∂2u( x, t) = ∂t ∂x2

This partial differential equation can be solved by standard procedure of ODE solver:

u:= operator(’u) → u (1) Type: BasicOperator

heat:= D(u(x,t),t)-D(u(x,t),x,2)=0 →

u, , ( x, t) + u, ( x, t) = 0 (2) − 1 1 2 Type: Equation Expression Integer

f:=operator(’f);trans:=rule(u(x,t)==f(x/sqrt(t))/sqrt(t)) → ’ f x √ u( x, t) == t (4) √t  Type: RewriteRule(Integer,Integer,Expression Integer)

eq1:=trans(lhs(heat))=0 →

2tf ,, x x√ t f , x tf x − √t − √t − √t = 0 (6)   2t2√t    Type: Equation Expression Integer

eq2:=lhs(eq1)*denom(lhs(eq1))/t →

2tf ,, x x√ t f , x tf x √ √ √ − t − t − t ( 12)   t     Type: Expression Integer

eq3:=subst(eq2,x=z*sqrt(t))=0 → ,, , 2 f ( z) zf ( z) f( z) = 0 ( 14) − − − Type: Equation Expression Integer

solve(eq3,f,z) →

z 2 z 2 z % P 2 − 4 − 4 particular = 0, basis = e  , e  e 4 d%P ( 15)      Z  Type: Union(Record(particular: Expression Integer,basi s: List Expression Integer),...)

sol:=k2*%.basis.1 + k1*%.basis.2 → z 2 z 2 z % P 2 − 4 − 4 k1 e  e 4 d%P + k2e  ( 16)  Z  Type: Expression Integer

sol2:=subst(%, z = x/sqrt(t))/sqrt(t) →

x 2 x x 2 % P 2 − 4t √t − 4t k1 e  e 4 d%P + k2e    ( 17) R √t Type: Expression Integer

sol3 := subst(%, [k1 = 0, k2 = 1/(2*sqrt(%pi))]) →

x 2 − 4t e  ( 18) 2√π√t Type: Expression Integer

→ x 2 /4t The last result, u( x, t)= e − /√ 2πt, is the famous heat kernel function. The following is another procedure with different method, i.e. by Laplace tranform.

u:= operator(’u) → u (1) Type: BasicOperator

heat:= D(u(x,t),t)-D(u(x,t),x,2)=0 →

u, , ( x, t) + u, ( x, t) = 0 (2) − 1 1 2 Type: Equation Expression Integer

eq1:=laplace(lhs(heat),x,s)=0 → 2 laplace( u , ( x, t) , x, s) s laplace( u( x, t) , x, s) + u , ( 0, t) + s u( 0, t) = 0 (3) 2 − 1 Type: Equation Expression Integer

f:=operator(’f);trans:=rule(laplace(u(x,t),x,s)==f(s,t)) → laplace( u( x, t) , x, s) == ’ f( s, t) (4) Type: RewriteRule(Integer,Integer,Expression Integer)

eq2:=trans(lhs(eq1)) → 2 laplace( u , ( x, t) , x, s) + u, ( 0, t) + s u( 0, t) s f( s, t) (5) 2 1 − Type: Expression Integer

eq3:=subst(%, D(laplace(u(x,t),x,s),t)=D(f(s,t),t))=0 → 2 u , ( 0, t) + f, ( s, t) + s u( 0, t) s f( s, t) = 0 (6) 1 2 − Type: Equation Expression Integer

f:=operator(’f) → f (7) Type: BasicOperator

With the boundary conditions, u(0, t) = ux(0, t) = 0, we have eq4:=D(f(t),t)-s^2*f(t)=0 → f , ( t) s 2 f( t) = 0 (8) − Type: Equation Expression Integer

solve(eq4,f,t) → 2 particular = 0, basis = e s t (9)  hType: Union(Record(particular:h ii Expression Integer,basis: List Expression Integer),...)

Lf:=C*%.basis.1 → 2 C e s t ( 10)  Type: Expression Integer

sol:=inverseLaplace(Lf,s,x) → "failed" ( 11 ) Type: Union("failed",...)

sol1:=integrate(Lf*exp(s*x),s=0..%plusInfinity) → "failed" ( 23) Type: Union(fail: failed,...)

integrate(exp(-s*s+s),s=0..%plusInfinity) → "failed" ( 29) Type: Union(fail: failed,...)

→ However, Axiom can not give any help at the last step (InverseLaplace f back)! L

Exercise 11. Reproduce the result of last problem by Maxima. Solution by maxima: •

Maxima 5.9.1 http://maxima.sourceforge.net Using Lisp GNU Common Lisp (GCL) GCL 2.6.6 (aka GCL) 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. (%i1) heat: ’diff(u,t) - ’diff(u,x,2) = 0

d d2 (%o12) u u = 0 d t − d x2 (%i13) s: f(x/sqrt(t))/sqrt(t) f x √t (%o13)   √t (%i14) eq1:subst(u=s,heat)

f x f x d √t d2 √t (%o19)     = 0 d t √t − d x2 √t (%i20) ev(%,diff)

2 d f x d f x f x d x 2 √t d t √t √t (%o20)   +    3  = 0 − √t √t − 2 t 2 (%i21) subst(x = z*sqrt(t), %);

2 d d 2 f( z) f z d ( t z ) d t ( ) f( z) (%o21) + 3 = 0 − √t √t − 2 t 2 In the last result, Maxima can NOT take operation of “Chain Rule”. Their take it by oneself! (%i22) eq2: (2*’diff(f(z),z,2)+z*’diff(f(z),z)+f(z))=0

d2 d (%o22) 2 f( z) + z f( z) + f( z) = 0 d z2 d z     (%i23) ode2(%,f(z),z)

z 2 4 i z z 2 √π i %k1 e− erf 2 (%o23) f( z) =%k2e− 4 − 2   (%i24) sol:subst(x/sqrt(t), z, rhs(%))/sqrt(t);

x 2 i x x 2 √π i %k1 e − 4 t erf 2 √ t %k2 e− 4 t (%o24) − 2   √t (%i25) subst([%k1 = 0, %k2 = 1/(2*sqrt(%pi))], %)

x 2 e− 4 t (%o25) 2 √π √t (%i26) diff(%,t)-diff(%,x,2)

(%o26) 0 (%i27)

Solve by laplace transform: Laplace method: ◦ Exercise 12. Solve the wave equation:

utt( x, t) = uxx ( x, t)

Solution: •

u:= operator(’u) → u ( 25) Type: BasicOperator

wave:=D(u(x,t),t,2)-D(u(x,t),x,2)=0 →

u, , ( x, t) u, , ( x, t) = 0 ( 26) 2 2 − 1 1 Type: Equation Expression Integer

f:=operator(’f) → f ( 18) Type: BasicOperator

trans:=rule(u(x,t)==c*f(x-t)+d*f(x+t)) → u( x, t) == d’ f( x + t) + c ’ f( x t) ( 32) − Type: RewriteRule(Integer,Integer,Expression Integer)

eq1:=trans(lhs(wave))=0 → 0 = 0 ( 33) Type: Equation Expression Integer

→ Exercise 13. Solve the following wave equation:

∂2 u ∂2 u = ∂t2 ∂x2 sin(2πt) , 0 6 t 6 1 u(0, t) = 0, t > 1  u( x, 0) = 0 for x > 0 ∂u ( x, 0) = 0 for x > 0 ∂t

Solution: u = H( t x) sin2π( t x) H( t x 1) sin2π( t x) where H( ) is Heaviside function. • − · − − − − − · By the laplace transform, we have d2 ( u) s 2 ( u) = L L dx2 st where ( u) = ∞ e u( x, t) dt. This implies L 0 − R ( u) = C esx + C e sx L 1 2 − As x , u 0. This implies ( u) = 0, and thus C = 0. And C is: → ∞ → L 1 2 1 st C2 = e − sin2πtdt 0 · Z 2π = 1 e x s 2 + 4π2 − −  Therefore 2π ( u) = e sx 1 e x L − s 2 + 4π2 − −  After all, the solution for this pde is:

2π u = 1 e sx 1 e x L− − s 2 + 4π2 − −   2π  = ∞ este sx 1 e x ds − s 2 + 4π2 − − Z0 = H( t x) sin2π( t x) H( t x 1) sin2π( t x) − · − − − − − 5. Yacas

Yacas is named as Yet Another CAS. It also owns the symbolic calculation capacity. Here is a short demo:

yacas] f(x):= x+Sin(x);

True yacas] D(x) f(x);

cos x + 1 yacas] Integrate(x,0,Pi) f(x);

π2 + 2 2 yacas] GnuPlot(-10,10,80,f(x)); True yacas]

The produced graph in the last command will be shown in another window. By snapshot of Gimp to catch the graph and embed into worksheet as:

Figure 8. You can download Yacas from http://www.xs4all.nl/~apinkus/yacas.html

6. QCL

QCL is a high level, architecture independent programming language for quantum computers, with a syntax derived from classical procedural languages like C or Pascal. This allows for the complete implementation and simulation of quantum algorithms (including classical components) in one consistent formalism. The TEXMACS interface is mainly useful for displaying quantum states in a readable way. For more information, see http://tph.tuwien.ac.at/~oemer/qcl.html

As suggest, users have better install the newest and binary version, now is 0.5, since it is difficult to compile from source. Moreover, if you install QCL from binary installation, confirm that all the library directory, lib, is under the directory at which the binary qcl locates.

QCL Quantum Computation Language (32 qubits, seed 1051277574) [0/32] 1 0 | i qcl> qureg a[1]; qcl> Rot(pi/4,a); [1/32] 0.92388 0 0.38268 1 | i − | i qcl> Mix(a); [1/32] 0.38268 0 + 0.92388 1 | i | i qcl> dump; STATE: 1 / 32 qubits allocated, 31 / 32 qubits free 0.38268 0 + 0.92388 1 | i | i qcl> include "shor.qcl"; qcl> operator dft(qureg q) { const n=#q; int i; int j;for i=1 to n { for j=1 to i-1 { if q[n-1] and q[n-j] {Phase(pi/2^(i-j));}} H(q[n-1]);} flip(q); } at "operator dft(qureg q) { c ...": illegal scope: Global symbol dft already defined qcl> dft(a); [1/32] 0.70711 0 + 0.70711 1 | i | i qcl> qcl>

7. R

R is an integrated suit of software facilities for data manipulation and graphical display. Many people use R as a statistics system. But the developers prefer to think of it as an implement within which many classical and modern statistical techniques have been implemented. If you are installed from source and it occurs the error caused by gc compilation, garbage collector, at the stage of make, just jump the process and keep going other make process. Here some examples are below:

> Welcome to the TeXmacs interface to R. To put the current graph in the TeXmacs buffer as an eps use v(). The functions plotv(), linesv(), and pointsv() are provided as a convenience. They do the regular function, and then insert the graph.

To change the size of the graph that is inserted to TeXmacs,just adjust the size of the X11 window. > qnorm(1/2,mean=0,sd=1) [1] 0 > x<-1:100 > y<-rnorm(x) > plot(x,y) > plot(x) > z<-sort(y) > plot(z) > plot(z,sort(y)) > hist(z) > summary(z) Min. 1stQu. Median Mean 3rdQu. Max. -3.798000 -0.608300 0.001963 -0.061880 0.583000 2.587000 > hist(y,seq(-4,3.5,0.2),prob=TRUE) > The result graphs of above are catched and shown below:

Figure 9.

Figure 10. Figure 11.

Figure 12. Figure 13.

Figure 14.

You can get it from http://www.r-project.org

8. Macaulay 2

Macaulay 2 is a new software system devoted to supporting research in and commutative algebra. The software is available now in source code for porting, and in compiled form for Linux, Sun OS, Solaris, Windows, and a few other unix machines. You can get it from http://www.math.uiuc.edu/Macaulay2 The mini demo as follows: Macaulay2 Session

Macaulay 2, version 0.9.2 --Copyright 1993-2001, D. R. Grayson and M. E. Stillman ---Factory 1.3b, copyright 1993-2001, G.-M. Greuel, et al. --Singular-Libfac 0.3.2, copyright 1996-2001, M. Messollen Macaulay 2 starting up macaulay2] macaulay2] R=QQ[x_1..x_4]

o2 = R o2 : PolynomialRing macaulay2] M=matrix{{x_1,x_2},{x_3,x_4}} x x o3 = 1 2 x x  3 4  o3 : Matrix macaulay2] D=det M

o4 = x x + x x − 2 3 1 4 o4 : R macaulay2] T=trace M

o5 = x1 + x4 o5 : R macaulay2] I=ideal{D,T}

o6 = –Function– ( x x + x x , x + x ) − 2 3 1 4 1 4 o6 : Ideal macaulay2] J=ideal M^2

2 2 o7 = –Function– ( x1 + x2 x3, x1 x3 + x3 x4, x1 x2 + x2 x4, x2 x3 + x4) o7 : Ideal macaulay2] radical I== radical J

o8 = true o8 : Boolean macaulay2] 9. Some Hints about Output

Among the tools packages supported by TEXMACS environment here, some experiences have to be kept in mind:

i. Maxima and Yacas are the powerful for symbolic calculation;

ii. Gnuplot and other CAS’s can used to plot the graphs in 2D, 3D and scientific data plots. But the Gnuplot is the best recommended software since the graph that it generates can be directly embedded into the worksheet in TEXMACS. iii. Also there are many powerful softwares with numerical abilities in Linux world, for example: Octave, Lab, Scilab and R (check your "session options" or the TEXMACS_INSTALL/lib exec). But Scilab owns its "terminal session" which is not easily embedded into the TEXMACS, Octave is the best choice due to its full accessibility. iv. 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 A TEXMACS is generally non-satisfied. If you want to generate HTML files, L TEX2html maybe A have some help. Consider to export L TEX format from TEXMACS and use the following latex2html command to translate TEX file into HTML and picture files:

> latex2html -nonavigation -split 0 filename.

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.

A Of course, you can export the worksheet from TEXMACS into L TEX format and remake the file by TEX system, for example: teTEX or MikTEX. Don’t forget to put TeXmacs.sty in the search tree of T X and execute texhash. This file can be found in the directory of $T X misc latex. Then E E MACS\ \ it will be no problem to LATEX this tex file into PostScript or PDF format. If you are interested in TEXMACS and CAS, more tm files can be found at: http://math.cgu.edu.tw:8080/Calculus

Note 5. There are several library as installing the latest Maxima, for example: odepack etc. Generally, you have to load them before use it. They are usually placed at “/usr/local/share/maxima/5.9.2/share” according to the prefix directory.

Maxima 5.9.2 http://maxima.sourceforge.net Using Lisp GNU Common Lisp (GCL) GCL 2.6.6 (aka GCL) 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. (%i23) load("plotdf")

(%o1) /usr/local/share/maxima/5.9.2/share/contrib/plotdf.lisp (%i2) plotdf(exp(-x)+y,[trajectory_at,2,-0.1])

(%o2) 0 (%i3) plotdf(y+%e^(-x),[trajectory_at,2,-0.1])

(%o3) 0

(%i2) load("pdiff")

(%o3) /usr/local/share/maxima/5.9.2/share/contrib/pdiff/pdiff.lisp (%i4) wave: ’diff(f(x,t),x,2)-’diff(f(x,t),t,2)=0

d2 d2 (%o4) f( x, t) f( x, t) = 0 d x2 − d t2 (%i5) subst([x=(u+v)/2,t=(v-u)/2],wave)

d2 v + u v u d2 v + u v u (%o5) 2 f , − 2 f , − = 0 ( v + u) 2 2 ( v u) 2 2 d − d − 4   4   (%i6) F: ’diff(f,u)

d (%o7) f d u (%i8) eq2:’diff(F,v)=0

d2 (%o8) f = 0 dudv (%i9) ode2(eq2,F,v)

d2 (%t9) f = 0 dudv Not a proper differential equation}

(%o9) false (%i10) subst([%c=f(v)],F)

(%o8) F (%i9) u:F(x-c*t)+G(x+c*t)

(%o1) G( x + c t) + F( x c t) − (%i2) diff(u,t,2)-c^2*diff(u,x,2)

d2 d2 d2 d2 (%o2) c2 G( x + c t) + F( x c t) + G( x + c t) + F( x c t) − d x2 d x2 − d t2 d t2 −   (%i3) ratsimp(%)

d2 d2 d2 d2 (%o3) c2 G( x + c t) + G( x + c t) c2 F( x c t) + F( x c t) − d x2 d t2 − d x2 − d t2 −     (%i4) ev(%,diff)

d2 d2 d2 d2 (%o4) c2 G( x + c t) + G( x + c t) c2 F( x c t) + F( x c t) − d x2 d t2 − d x2 − d t2 −     (%i5)