# Symbolic algebra and Mathematics with Xcas

### Renée De Graeve, Bernard Parisse1, Jay Belanger2 Sections written by Luka Marohnić3

© 2002, 2007 Renée De Graeve, Bernard Parisse
`renee.degraeve@wanadoo.fr`
`bernard.parisse@ujf-grenoble.fr`

# Chapter 2  Introduction

## 2.1  Notations used in this manual

In this manual, the information that you enter is typeset in typewriter font. User input typically takes one of three forms:

• Commands that you enter on the command line.
For example, to compute the sin of π/4, you can type
sin(pi/4)
• Commands requiring a prefix key.
These are indicated by separating the prefix key and the standard key with a plus +. For example, to exit an Xcas session, you can type the control key along with the q key, which will be denoted
Ctrl+Q
When denoting menu items, submenus are connected using ▸. For example, from within Xcas you can choose the File menu, then choose the Open submenu, and then choose the File item. This will be indicated by
File Open File

When describing entering a command, specific values that you enter for arguments are in typewriter font, while argument placeholders that should be replaced by actual values are in italics. Optional arguments will be enclosed by angle brackets. For example, you can find the derivative of an expression with the diff command (see Section 6.19.4), which takes the form diff(expr ⟨,x]) where expr is an expression and x is a variable or list of variables. If the optional variable is omitted, then it will default to x. A specific example is diff(x*sin(x),x).

The index uses different typefaces for different parts of the language. The commands themselves are written with normal characters, command options are written in italics and values of commands or options are written in typewriter font. For example (as you will see later), you can draw a blue parabola with the command

plotfunc(x^2,color = blue)

In the index, you will see

• plotfunc, the command, written in normal text.
• color, the command option, written in italics.
• blue, the value given to the option, written in typewriter font.

## 2.2  Interfaces for the giac library

The giac library is a C++ mathematics library. It comes with two interfaces you can use directly; a graphical interface and a command-line interface. All interfaces can do symbolic and numeric calculations, use giac’s programming language, and have a built in help function.

The graphical interface is called Xcas, and is the most full-featured interface. Xcas has additional help features to make it easy to use, plus it has a built-in spreadsheet, it can do dynamic geometry and it can do turtle graphics. The output given by this interface is typeset; for example:
Input:

sqrt(1/2)

Output:

 2
2

The command-line interface can be run inside a terminal, and in a graphical environment can also draw graphs. The output given by this interface is in text form; for example:
Input:

sqrt(1/2)

Output:

sqrt(2)/2

There is also a web version, which can be run through a javascript-enabled browser (it works best with Firefox), either over the internet or from local files. Other programs (for example, TeXmacs) have interfaces for the command-line version. Some of these interfaces, such as the two mentioned here, typeset their output.

# Chapter 3  The Xcas interface

## 3.1  The entry levels

The Xcas interface can run several independent calculation sessions, each session will be contained in a separate tab. Before you understand the Xcas interface, it would help to be familiar with the components of a session.

Each session can have any number of input levels. Each input level will have a number to the left of it; the number is used to identify the level. Each level can have one of the following:

• A command line.
This is the default; you can open a new command line with Alt+N.
You can enter a giac command (or a series of commands separated by semicolons) on a command line and send it to be evaluated by hitting enter. The result will then be displayed, and another command line will appear. You can also scroll through the command history with Ctrl+Up and Ctrl+Down.

If the output is a number or an expression, then it will appear in blue text in a small area below the input region; this area will be an expression editor (see Section 4.3). There will be a scrollbar and a small M to the right of this area; the M is a menu which gives you various options.

If the output is a graphic, then it will appear in a graphing area below the input region. To the right of the graphic will be a control panel which you can use to manipulate the graphic (see Section 8.2).

• An expression editor.
See Section 4.3. You can open an expression editor with Alt+E.
• A two-dimensional geometry screen.
See Section 8.2. You can open a two-dimensional geometry screen with Alt+G. This level will have a screen, as well as a control panel, menus and a command line to control the screen.
• A three-dimensional geometry screen.
See Section 8.2. You can open a three-dimensional geometry screen with Alt+H. This level will have a screen, as well as a control panel, menus and a command line to control the screen.
• A turtle graphics screen.
You can open a turtle graphics screen with Alt+D. This level will have a screen, as well as a program editor and command line.
See Section 4.5. You can open a spreadsheet with Alt+T. A spreadsheet can open a graphic screen.
• A program editor.
See Section 12.1.1. You can open a program editor with Alt+P.
• A comment line.
See Section 4.2. You can open a comment line with Alt+C.

Levels can be moved up and down in a session, or even moved to a different session.

The level containing the cursor is the current level. The current level can be evaluated or re-evaluated by typing enter.

You can select a level (for later operations) by clicking on the number in the white box to the left of the level. Once selected, the box containing the number turns black. You can select a range of levels by clicking on the number for the beginning level, and then holding the shift key while you click on the number for the ending level.

You can copy the instructions in a range of levels by selecting the range, and then clicking the middle mouse button on the number of the target level.

## 3.2  The starting window

When you first start Xcas, you get a largely blank window.

The first row will consist of the main menus; you can save and load Xcas sessions, configure Xcas and its interface and run various commands with entries from these menus.

The second row will contains tabs; one tab for each session that you are running in Xcas. Each tab will have the name of its session, or Unnamed if the session has no name. The first time you start Xcas, there will be only one session, which will be unnamed.

The third row will contain various buttons.

• The first button, ?, opens the help index (The same as the HelpIndex menu entry; see Section 3.3). If there is a command on the command line, the help index will open at this command.
• The second button, Save, saves the session in a file. The first time you click on it you will be prompted for a file name ending in .xws in which to save the session. The button will be pink if the session is not saved or if it has changed since the last change, it will be green once the session is saved. The name in the title will be the name of the file used to save the session.
• The third button, which in the picture above is
Config: exact real RAD 12 xcas 6.2148M,
is a status line indicating the current Xcas configuration (see Section 3.5). If the session is unsaved, it will begin with Config:; if the session is saved in a file filename.xws, this button will begin with Config filename.xws:. Other information on this status line:
1. exact or approx
This tells you whether Xcas will give you exact values, such as √2, when possible or gives you decimal approximations, such as 1.4142135. (See Section 3.5.4.)
2. real, cplx or CPLX.
When this shows real (for example), then Xcas will by default only find real solutions of equations. When this shows cplx, then Xcas will find complex solutions of equations. When this shows CPLX, then Xcas will regard variables as complex; for example, it won’t simplify re(z) (the real part of the variable z) to z. (See sections 3.5.5 and 3.5.6.)
This tells you whether angles, as in trigonometric arguments, are measured in radians or degrees. (See Section 3.5.3.)
4. An integer.
This tells you how many significant digits will be used in floating point calculations. (See Section 3.5.1.)
5. xcas, python ^=**, python ^=xor, maple, mupad, or ti89.
This tells you what syntax Xcas will use. Xcas can be set to emulate the languages of Python, Maple, MuPAD, or the TI89 series of calculators. (See Section 3.5.2.)
6. The last item tells you how much memory Xcas is using.
Clicking on this status line button opens a window where you can configure the settings shown on this line as well as some other settings; you can also open the window with the menu item CfgCAS Configuration (see Section 3.5.7).
• The fourth button, STOP (in red), is used to halt a computation which is running on too long.
• The fifth button, Kbd, toggles an on-screen scientific keyboard at the bottom of the window.
Along the right hand side of the keyboard are some keys that can be used to change the keyboard.
• The X key hides the keyboard, just like pressing the Kbd button again.
• The cmds key toggles a menu bar at the bottom of the screen which can be used as an alternate menu or persistent submenu. This bar will contain buttons home, <<, some menu titles, >>, var, cust and X.

The << and >> buttons scroll through menu items. Clicking on one of the menu buttons will perform the appropriate action or replace the menu items by its submenu items. When submenu items appear, there will also be a BACK button to return to the previous menu. Clicking on the home button returns the menu buttons to the main menu.

After the menu buttons is a var button. This replaces the menu buttons by buttons representing the variables that you have defined. After that is a cust button, which displays commands that you store in a list variable CST (see section 5.4.10).

The last button, X, closes the menu bar.

• The msg key brings up a message window at the bottom of the window which will give you helpful messages; for example, if you save a graphic, it will tell you the name of the file it is saved in and how to include it in a LATEX file.
• The abc key toggles the keyboard between the scientific keyboard and an alphabetic keyboard.
• The fifth button, X, closes the current session.

## 3.3  Getting help

Xcas is an extensive program, but using it is simplified with several different ways of getting help. The help menu (see section 3.4.4) has several submenus for various forms of help, some of which are mentioned below.

The menus provide different ways to work with Xcas and its sessions, as well as ways of inserting functions and constants into the current session. Selecting a menu item corresponding to a function or constant brings up the help index (see section 3.3) with the chosen function or constant selected.

## 3.7  Translating to other computer languages

Xcas can translate a session, or parts of a session, to other computer languages; notably LATEX and MathML.

# Chapter 4  Entry in Xcas

## 4.1  Suppressing output: nodisp:;

If you enter a command into Xcas, the result will appear in the output box below the input. If you enter

a:= 2+2

then

 4

will appear in the output box.

The nodisp command is used to evaluate an expression and suppress the output.

• nodisp takes one argument:
expr, an expression.
• nodisp(expr) evaluates expr but displays Done in place of the result.

Example.
Input:

nodisp(a:= 2+2)

Output:

Done

and a will be set to 4.

An alternate way of suppressing the output is to end the input with :;.

Example.
Input:

b:= 3+3:;

Output:

Done

and b will be set to 6.

You can annotate an Xcas session by adding comments. You can enter a comment on the current line at any time by typing Alt+C. The line will appear in green text and conclude when you type Enter. Comments are not evaluated and so have no output. If you have started entering a command when you begin a comment, the command line with the start of the command will be pushed down so that you can finish it when you complete the comment.

You can open the browser using a comment line by entering the web address beginning with the @ sign. If you enter the comment line

 The Xcas homepage is at @www-fourier.ujf-grenoble.fr/~parisse/giac.html

To add a comment to a program, rather than a session, you can use the comment command.

• comment takes one argument:
str, a string.
• comment(str) makes str a comment.

Alternatively, any part of a program between // and the end of the line is a comment. So both

bs():= {comment("Hello"); return "Hi there!";}

and

 bs():= { // Hello return "Hi there!";}

are programs with the comment "Hello".

## 4.3  Editing expressions

You can enter expressions on the command line, but Xcas also has a built-in expression editor that you can use to enter expressions in two dimensions, the way they normally look when typeset. When you have an expression in the editor, you can also manipulate subexpressions apart from the entire expression.

## 4.4  Previous results: ans

The ans command returns the results of previous commands.

• ans takes one optionaly argument:
Optionally, n, an integer (the number of the command beginning with 0).
• ans(n) returns the corresponding result; in particular, ans(-1) returns the previous result.

Example.
If the first command that you enter is:
Input:

2+5

resulting in
Output:

 7

then later references to ans(0) will evaluate to 7.

Note that the argument to ans doesn’t correspond to the line number in Xcas. For one thing, the line numbers begin at 1. What’s more, if you go back and re-evaluate a previous line, then that will become part of the commands that ans keeps track of.

If you give ans a negative number, then it counts backwards from the current input. To get the latest output, for example, you can use ans(-1). With no argument, ans() will also return the latest output.

Similarly, the quest command returns the previous inputs. Since these will often be simplified to be the same as the output, quest(n) sometimes has the same value as ans(n).

You can also use Ctrl plus the arrow keys to scroll through previous inputs. With the cursor on the command line, Ctrl+uparrow will go backwards in the list of previous commands and display them on the current line, and Ctrl+downarrow will go forwards.

# Chapter 5  CAS building blocks

## 5.1  Numbers

Xcas works with both real and complex numbers. The real numbers can be integers, rational numbers, floating point numbers or symbolic constants.

You can enter an integer by simply typing the digits.
Input:

1234321

Output:

 1234321

Alternatively, you can enter an integer in binary (base 2) by prefixing the digits (0 through 1) with 0b, in octal (base 8) by prefixing the digits (0 through 7) with 0 or 0o, and in hexadecimal (base 16) by prefixing the digits (0 through 9 and a through f) with 0x. (See Section 6.4.1.)
Input:

0xab12

Output:

 43794

You can enter a rational number as the ratio of two integers.
Input:

123/45

Output:

 41 15

The result will be put in lowest terms. If the top is a multiple of the bottom, the result will be an integer.
Input:

123/3

Output:

 41

A floating point number is regarded as an approximation to a real number. You can enter a floating point number by writing it out with a decimal point.
Input:

123.45

Output:

 123.45

You can also enter a floating point number by entering a sequence of digits, with an optional decimal point, followed by e and then an integer, where the e represents “times 10 to the following power.”
Input:

1234e3

Output:

 1.234e+06

Floating point numbers with a large number of digits will be printed with e notation; you can control how other floats are displayed (see Section 3.5.7, item 7). An integer or rational number can be converted to a floating point number with evalf (see Section 6.8.1).

A complex number is a number of the form a+bi, where a and b are real numbers. The numbers a and b will be the same type of real number; one type will be converted to the other type if necessary (an integer can be converted to a rational number or a floating point number, and a rational number can be converted to a floating point number).
Input:

3 + 1.1i

Output:

 3+1.1i

## 5.2  Symbolic constants: epiinfinityinfieuler_gamma

Xcas has the standard constants given by built-in symbols, given in the following table.

 Symbol Value e (or %e) the number exp(1) pi (or %pi) the number π infinity unsigned ∞ +infinity (or inf) +∞ -infinity (or -inf) −∞ i (or %i) the complex number i euler_gamma Euler’s constant γ; namely, limn→∞(∑k=1n − ln(n))

Since these numbers cannot be written exactly as standard decimal numbers, they are necessarily left unevaluated in exact results (see Section 3.5.4).
Input:

2*pi

Output:

 2π

Input:

2.0*pi

Output:

 6.28319

You can also use evalf (see Section 6.8.1), for example, to approximate one of the real-valued constants to as many decimal places as you want.
Input:

evalf(pi,50)

Output:

 3.14159

# Chapter 6  The CAS functions

## 6.5  Integers (and Gaussian Integers)

Xcas can manage integers with unlimited precision, such as the following (see Section 6.6.1):
Input:

factorial(100)

Output:

 9332621544394415268169923885626670049071596826438162 1468592963895217599993229915608941463976156518286253 697920827223758251185210916864000000000000000000000000

Gaussian integers are numbers of the form a+ib, where a and b are in ℤ. For most functions in this section, you can use Gaussian integers in place of integers.

## 6.9  Permutations

A permutation p of size n is a bijection from [0..n−1] to [0..n−1] and is represented by the list: [p(0),p(1),p(2)… p(n−1)].
For example, the permutation p represented by [1,3,2,0] is the function from [0,1,2,3] to [0,1,2,3] defined by:

 p(0)=1, p(1)=3, p(2)=2, p(3)=0

A cycle c of size p, represented by the list [a0,…,ap−1] (0≤ akn−1), is the permutation such that

 c(ai)=ai+1  for (i=0..p−2),    c(ap−1)=a0,    c(k)=k  otherwise

For example, the cycle c represented by the list [3,2,1] is the permutation c defined by c(3)=2, c(2)=1, c(1)=3, c(0)=0 (i.e. the permutation represented by the list [0,3,1,2]).

## 6.10  Complex numbers

Note that complex numbers, as well as being numbers, are used to represent points in the plane (see Section 13.6.2). Some functions and operators which work on complex numbers also work on points.

## 6.14  Operators or infixed functions

An operator is an infixed function. For example, the arithmetic functions +, -, *, /, and ^ are operators. (See Section 6.8.2 and Section 6.10.1.)

## 6.18  Limits: limit

The limit command computes limits, both at numbers and infinities, and in the real case it can compute one-sided limits.

• limit takes three mandatory and one optional argument.
• expr, an expression.
• x, the name of a variable.
• a, the limit point.
• Optionally, side (either 0, -1 or 1), to specify which side to take a one-sided limit (by default side=0).
• limit(expr,x,a ⟨,side) returns the limit of expr as x approaches a.
• If side is 0 (the default), then the ordinary limit is returned.
• If side is -1, then the limit from the left (x<a) is returned.
• If side is 1, then the limit from the right (x>a) is returned.

Remark:
It is also possible to put x=a as argument instead of x,a; limit(expr,var=pt[,side]) is equivalent to limit(expr,var,pt[,side]).

Examples.

• Input:
limit(1/x,x,0,-1)
or:
limit(1/x,x=0,-1)
Output:  −∞
• Input:
limit(1/x,x,0,1)
or:
limit(1/x,x=0,1)
Output:  +∞
• Input:
limit(1/x,x,0,0)
or:
limit(1/x,x,0)
or:
limit(1/x,x=0)
Output:  ∞
(Note that ∞ or infinity without an explicit + or - represents unsigned infinity.) Hence, abs(1/x) approaches +∞ when x approaches 0.

Exercises.

• Find, for n>2, the limit as x approaches 0 of:
 ntan(x)−tan(nx) sin(nx)−nsin(x)
Input:
limit((n*tan(x)-tan(n*x))/(sin(n*x)-n*sin(x)),x=0)
Output:  2
• Find the limit as x approaches +∞ of
 √
x+ √
x+ x
 x
Input:
limit(sqrt(x+sqrt(x+sqrt(x)))-sqrt(x),x=+infinity)
Output:
 1 2
• Find the limit as x approaches 0 of
 1+x+x2/2
−exp(x/2)
(1−cos(x))sin(x)
Input:
limit((sqrt(1+x+x^2/2)-exp(x/2))/((1-cos(x))*sin(x)),x,0)
Output:
 1 6

## 6.23  Trigonometry

Xcas can evaluate the trigonometric functions in either radians or degrees (see Section 6.16.2). It can also manipulate them algebraically.

## 6.28  Arithmetic and polynomials

Polynomials are represented by expressions or by lists of coefficients in decreasing power order. In the first case, for instructions requiring a main variable (like extended gcd computations), the variable used by default is x if not specified. For coefficients in ℤ/nℤ, use % n for each coefficient of the list or apply it to the entire expression defining the polynomial.

## 6.34  Computing in ℤ/pℤ or in ℤ/pℤ[x]

The way to compute over ℤ/pℤ or over ℤ/pℤ[x] depends on the syntax mode:

• In Xcas mode, an object n over ℤ/pℤ is written n % p.
The representation is the symmetric representation:
11%13 returns -2%13.

Examples.

• An integer n in ℤ/13ℤ
n:=12%13.
• a vector V in ℤ/13ℤ
V:=[1,2,3]%13 or V:=[1%13,2%13,3%13].
• a matrix A in ℤ/13ℤ
A:=[[1,2,3],[2,3,4]]%13 or
A:=[[1%13,2%13,3%13],[[2%13,3%13,4%13]].
• a polynomial A in ℤ/13ℤ[x] in symbolic representation
A:=(2*x^2+3*x-1)%13 or
A:=2%13*x^2+3%13*x-1%13.
• a polynomial A in ℤ/13ℤ[x] in list representation
A:=poly1[1,2,3]%13 or A:=poly1[1%13,2%13,3%13].

To recover an object o with integer coefficients instead of modular coefficients, input o % 0. For example:
Input:

 o:=4%7;: o%0

Output:

 −3

Remark. Most Xcas functions that work on integers or polynomials with integer coefficients will often work the same on ℤ/pℤ or ℤ/pℤ[x], with the obvious exception that the input and output will be modular. They will be listed in the remaining subsections. For some commands in ℤ/pℤ or in ℤ/pℤ[x], p must be a prime integer.

• In Maple mode, integers modulo p are represented like usual integers instead of using specific modular integers. To avoid confusion with normal commands, modular commands are written with a capital letter (inert form) and followed by the mod command.

The Maple commands will be discussed in Section 6.35.

## 6.35  Computing in ℤ/pℤ[x] using Maple syntax

You can set Xcas to work in Maple mode rather than native Xcas mode (see Section 3.5.2).

## 6.43  Tables with strings as indices: table

A table is a map (associative container) used to store information associated to indices which are much more general than integers, such as strings or sequences. For example, you can use one to store a table of phone numbers indexed by names.

In Xcas, the indices in a table may be any kind of Xcas objects. Access is done by a binary search algorithm, where the sorting function first sorts by type then uses an order for each type (e.g. < for numeric types, lexicographic order for strings, etc.)

The table command creates a table.

• table takes an unspecified number of arguments:
seq, a list or sequence of equalities of the form index_name=element_value.
• table(seq) returns a table. The elements of the table can be retrieved using index bracket notation; If T is the name of the table, then T(index_name) returns element_value.

Example.
Input:

T:=table(3=-10,"a"=10,"b"=20,"c"=30,"d"=40):;

Input:

T["b"]

Output:

 20

Input:

T[3]

Output:

 −10

Remark.
Tables can be created and the elements of a table can be changed using the := assignment.

• If T is a symbolic variable then the assignment T(index_name:=element_value will create a table T with one element.
• If n is an integer, then the assignment T(n):=obj will do the following:
• If the variable T was assigned to a list or a sequence, then the nth element of T is modified.
• if the variable T was not assigned, a table T is created with one entry (corresponding to the index n). Note that after the assignment T is not a list, despite the fact that n is an integer.

## 6.49  Matrix factorizations

Note that most matrix factorization algorithms are implemented numerically, only a few of them will work symbolically.

## 6.50  Different matrix norms

See Section 6.42.1 for different norms on vectors.

## 6.51  Isometries

An isometry of ℝn is a distance-preserving map. In ℝ2, the isometries are made up of:

• reflection across a line.
• translation.

In ℝ3, the isometries are made up of:

• reflection across a plane.
• translation.

An isometry is direct if it preserves orientation (it doesn’t involve a reflection), otherwise it is indirect.

An n× n matrix A determines an isometry of the function f:ℝn→ℝn by f(x) = Ax) is an isometry. Such isometries fix the origin, so they can’t involve translation, can only rotate about the origin, and the line or plane of reflection will pass through the origin.

An isometry in ℝ2 can be characterized by:

• The angle of rotation (for a direct isometry) or a normal to the line of reflection (for an indirect isometry).
• +1 or -1 to indicate whether it is direct or indirect; +1 for direct and -1 for indirect.

An isometry in ℝ3 can be characterized by:

• The direction of an axis of rotation.
• The angle of rotation (for a direct isometry) or a normal to the plane of reflection (for an indirect isometry).
• +1 or -1 to indicate whether it is direct or indirect; +1 for direct and -1 for indirect.

## 6.52  Linear Programming

Linear programming problems involve maximizing a linear functionals under linear equality or inequality constraints. The simplest case can be solved directly by the so-called simplex algorithm. Most cases require you to solve an auxiliary linear programming problem to find an initial vertex for the simplex algorithm.

## 6.56  Linear systems

The augmented matrix of the system A · X=b is either the matrix obtained by gluing the column vector b to the right of the matrix A (as with border(A,tran(b))), representing A · X=b, or the matrix obtained by gluing the column vector −b to the right of the matrix A, representing A· xb = 0.

## 6.57  Differential equations

This section is limited to symbolic (or exact) solutions of differential equations. For numeric solutions of differential equations, see odesolve (Section 10.3.5). For graphic representation of solutions of differential equations, see plotfield (Section 8.18), plotode (Section 8.19) and interactive_plotode (Section 8.20).

## 6.60  The day of the week: dayofweek

The dayofweek command finds the day of the week for any date after 15 October, 1582.

• dayofweek takes as arguments three arguments:
• d, an integer representing the day of the month.
• m, an integer representing the month.
• y, an integer representing the year.
The date represented should be after 15 October 1582.
• dayofweek(d,m,y) returns an integer from 0 to 6; 0 representing Sunday, 1 representing Monday, etc.

Examples.

• Input:
dayofweek(1,10,2014)
Output:  3
This means that 1 October, 2014 was a Wednesday.
• Input:
dayofweek(15,10,1582)
Output:  5
This indicates that 15 October 1582 was on a Friday.

The Gregorian calendar, the calendar used by most of the world, was introduced on 15 October 1582. Before that, the Julian calendar was used, which had a leap year every four years and so used years with an average of 365.25, which is slightly off from the actual value of about 365.242 days. To deal with this, the Gregorian calendar was introduced, where a leap year is a year which is divisible by 4, but not divisible by 100 unless it is also divisible by 400. This gives an average length of year that is accurate to within 1 day every 3000 years.

Many countries switched from the Julian calendar to the Gregorian calendar after 4 October 1582 in the Julian calendar, and the next day was 15 October 1582.

# Chapter 7  Metric properties of curves

## 7.1  The center of curvature

Let Γ be a curve in space parameterized by a continuously differentiable function, and M0 be a point on the curve. The curve will have an arclength parameterization; namely, it can be parameterized by a function M(s), where M(0) = M0 and |s| is the length of the curve from M0 to M(s), in the direction of the curve if s>0 and the opposite direction if s<0.

For such a Γ, the vector T(s) = M′(s) will be the unit tangent to the curve at M(s), and N(s) = T′(s) will be perpendicular to the tangent. The circle through M(s) with center at M(s) + N(s) is called the osculating circle to Γ at M(s). Informally, the osculating circle is the circle through M(s) which most closely approximates Γ. The set of all centers of curvature is another curve, called the evolute of Γ.

The radius of the osculating circle is |N(s)| and is called the radius of curvature of Γ at M(s). The reciprocal of this is called the curvature of Γ at M(s).

## 7.2  Computing the curvature and related values: curvatureosculating_circleevolute

A curve can be described in Xcas with a parametrization or with a curve object. Various curve objects are described in chapters 13 and 14. The commands in this section can work with curves described either way. You can get the equation of a curve object with the equation command (see Section 13.13.7).

The curvature command finds the curvature of a curve. The curve can be given as an object or by a parameterization.

To find the curvature from a parameterization:

• curvature takes two mandatory arguments and one optional argument:
• C, a curve.
• t, the parameter of the curve.
• Optionally, t0, a value of the parameter.
• curvature(C,t ⟨, t0) returns the curvature of the curve; if t0 is given, the curvature is given at the point it specifies, otherwise the curvature is given as a function of the parameter.

To find the curvature from a curve object:

• curvature takes two arguments:
• C, a curve.
• p, a point on the curve.
• curvature(C,p) returns the curvature of C at the point p.

Examples.

• Input:
trigsimplify(curvature([5*cos(t),5*sin(t)],t))
Output:
 1 5
• Input:
curvature([2*cos(t),3*sin(t)],t)
Output:

6 cos2t+6 sin2t
 9 cos2t+4 sin2t
 ⎛ ⎝ 9 cos2t+4 sin2t ⎞ ⎠ 2
• Input:
curvature([2*cos(t),3*sin(t)],t,pi/2)
Output:
 3 4
• Input:
curvature(plot(x^2),point(1,1))
(see Section 8.5 and Section 13.6.2.) Output:
 2 25
 5

The osculating_circle command finds and draws the osculating circle of a curve.

To find the osculating circle from a parameterization:

• osculating_circle takes three arguments:
• C, a curve.
• t, the parameter of the curve.
• t0, a value of the parameter.
• osculating_circle(C,t,t0) draws and returns the osculating circle of the curve at the point specified by t0.

To find the osculating circle from a curve object:

• osculating_circle takes two arguments:
• C, a curve.
• p, a point on the curve.
• osculating_circle(C,p) draws and returns the osculating circle of C at the point p.

Examples.

• Input:
osculating_circle(plot(x^2),point(1,1))
Output:
• Input:
equation(osculating_circle(plot(x^2),point(1,1)))
Output:

x+4
2+

y 7 2

 2
= 125 4
• Input:
equation(osculating_circle([t^2,t^3],t,1))
Output:

x+ 11 2

 2
+

y 16 3

 2
= 2197 36

The evolute command finds and draws the evolute of a curve.

To find the evolute from a parameterization:

• evolute takes two arguments:
• C, a curve.
• t, the parameter of the curve.
• evolute(C,t) draws and returns the evolute of the curve.

To find the evolute from a curve object:

• evolute takes one argument:
C, a curve.
• evolute(C) draws and returns the evolute of C.

Examples.

• Input:
evolute(plot(x^2))
Output:
• Input:
equation(evolute(plot(x^2)))
Output:  27 x2−16 y3+24 y2−12 y+2=0
• Input:
equation(evolute([t^2,t],t))
Output:  16 x3−24 x2+12 x−27 y2−2=0

# Chapter 8  Graphs

## 8.1  Generalities

Most graph instructions take expressions as arguments. A few exceptions (mostly Maple-compatibility instructions) also accept functions. Some optional arguments, like color, thickness, can be used as optional attributes in all graphic instructions. They are described below.

If a graph depends on a user-defined function, you may want to define the function when the parameter is a formal variable. For this, it can be useful to test the type of the parameter while the function is being defined. (See Chapter Section 12 for information about programming in Xcas.)

For example, suppose f and g are defined by:

 `f(x):= {` ` if (type(x)!=DOM_FLOAT) return 'f'(x);` ` while(x>0){ x--;}` ` return x;` `}`

and

 `g(x):= {` ` while(x>0){ x--;}` ` return x;` `}:;`

Graphing these (see Section 8.4.1):
Input:

 F:= plotfunc(f(x)) G:= plotfunc(g(x))

they will both produce the same graph. However, the graphic G won’t be reusable. Entering:
Input:

F

reproduces the graph, but entering:
Input:

G

produces the error:
Output:

 "Unable to eval test in loop: x>0.0 Error: Bad Argument Value Error: Bad Argument Value"

Internally, F and G contain the formal expressions f(x) and g(x), respectively. When Xcas tries to evaluate F and G, x has no value and so the test x > 0 produces an error in g(x), but the line `if (type(x)!=DOM_FLOAT) return 'f'(x);` avoids this problem in f(x).

## 8.2  The graphic screen

A graphic screen, either two- or three-dimensional as appropriate, automatically opens in response to a graphic command. Alternatively, you can open a graphic screen with its own command line with keystrokes; Alt-g for a two-dimensional screen and Alt-h for a three-dimensional screen. The graphic screen will have an array of buttons at the top right.

• There will be red arrows for moving the image in the x direction.
• There will be green arrows for moving the image in the y direction.
• There will be blue arrows for zooming in and out in a two-dimensional screen, and moving the image in the z direction in a three-dimensional screen.
• There will be in and out buttons for zooming in and out.
• There will be a _|_ button to orthonormalize the graphic.
• There will be a ▸| button to start and stop animations.
• There will be an auto button to do automatic scaling.
• There will be a cfg button which will bring up a configuration screen (see Section 3.5.7).
• View which has entries which do the same as the buttons.
• Trace for working with traces.
• Animation for working with animations.
• 3-d for working with three-dimensional graphics.
• Export/Print to export and print the graphic.

The image can also be moved in the screen by clicking and dragging with the mouse. Scrolling with the mouse will also zoom the images.

## 8.3  Graph and geometric objects attributes

There are two kinds of attributes for graphs and geometric objects: global attributes of a graphic scene and individual attributes.

## 8.5  2d graph for Maple compatibility: plot

The plot command is a Maple-compatible way to draw the graph of a one-variable function.

• plot takes one mandatory argument and two optional arguments:
• func, a function or an expression involving one variable.
• Optionally, var the name of the variable in the expression (if func is an expression), which can also specify a range of values var=a..b (by default it is x). If func is a function, the optional second argument can simply be a range a..b for the variable.
• Optionally, opt, which can be xstep=n to specify the discretization step or nstep=n to specify the number of points used to graph.
• plot(expr ⟨ ,var, opt) draws the graph.

Examples.

• Input:
plot(x^2-2,x)
Output:
• Input:
plot(x^2-2,xstep=1)
or:
plot(x^2-2,x,xstep=1)
Output:
• Input:
plot(x^2-2,x=-2..3,nstep=30)
Output:

## 8.6  3d surfaces for Maple compatibility plot3d

The plot3d command is a Maple-compatible way to draw a surface. It can plot the graph of a function of two variables or a surface given by a parameterization.

To draw the graph of a function:

• plot3d takes three arguments:
• func, a function or an expression involving two variables.
• x and y, the names of the variable in the expression (if func is an expression) which can also specify a range of values for each variable.

If func is a function, this argument is optional, and are the ranges a..b for the variables.

If the ranges are not given, the default values are taken from the graph configuration (see Section 3.5.8).

• plot3d(func,x,y) draws the graph.

Example.
Input:

plot3d(x*y,x,y)

Output:

To draw a parameterized surface:

• plot3d takes one mandatory argument and two optional arguments:
• funcs, a list of three functions or three expressions involving two variables.
• u and v, the names of the variable in the expression (if funcs is a list of expressions), which can also specify a range of values for each variable.

If funcs is a list of functions, this argument is optional, and are the ranges a..b for the variables.

If the ranges are not given, the default values are taken from the graph configuration (see Section 3.5.8).

• plot3d(funcs,u,v) draws the surface.

Examples.

• Input:
plot3d([v*cos(u),v*sin(u),v],u,v)
Output:
• Input:
plot3d([v*cos(u),v*sin(u),v],u=0..pi,v=0..3)
Output:

## 8.8  Graphing inequalities with two variables: plotinequationinequationplot

The plotinequation command plots the region of the plane where given inequalities hold.

• plotinequation takes two arguments:
• ineqs, a list of inequalities in two variables.
• vars, a list of variables var or variables var=a..b with their ranges of values. Note that if the ranges are not specified, Xcas takes the default values of X-,X+,Y-,Y+ defined in the general graphic configuration (CfgGraphic configuration, see Section 3.5.8).
• plotinequation(ineqs,vars) draws the points of the plane whose coordinates satisfy the inequalities ineqs.

Examples.

• Input:
plotinequation(x^2-y^2<3, [x=-2..2,y=-2..2],xstep=0.1,ystep=0.1)
Output:
• Input:
plotinequation([x+y>3,x^2<y], [x-2..2,y=-1..10],xstep=0.2,ystep=0.2)
Output:

## 8.9  The area under a curve: area

The area command approximates the area under a graph.

• area takes four arguments:
• expr, an expression f(x).
• var=a..b, the variable with a range.
• n, a positive integer.
• method, the approximation method to use, which can be one of:
• trapezoid
• left_rectangle
• right_rectangle
• middle_point
• simpson
• rombergt (Romberg with the trapezoid method)
• rombergm (Romberg with the midpoint method)
• gauss15 (The 15 point Gaussian quadrature)
• area(expr,var=a..b,n,method) returns an approximation to the area under the graph over the given interval, using the specified method with n subdivisions (or 2n subdivisions for rombert, rombergm and gauss15).

Examples.

• Input:
area(x^2,x=0..1,8,trapezoid)
Output:  0.335938
• Input:
area(x^2,x=0..1,8,rombergm)
Output:  0.333333
• Input:
area(x^2,x=0..1,3,gauss15)
Output:  0.333333
• Input:
area(x^2,x=0..1)
Output:
 1 3

## 8.10  Graphing the area below a curve: plotareaareaplot

The plotarea command draws the area below a graph.
areaplot is a synonym for plotarea.

• plotarea takes two mandatory arguments and two optional arguments:
• expr, an expression representing the function to graph.
• var=a..b, the variable and the range of values.
• Optionally, n.
• Optionally, method, a method to approximate the region under the graph, which can be one of:
• trapezoid
• rectangle_left
• rectangle_right
• middle_point
• plotarea(expr,var=a..b) draws and shades the area between the graph of expr and the y-axis for a < var < b.
• plotarea(expr,var=a..b ⟨, n, method) draws and shades the region used by the numeric approximation method method for area between the graph of expr and the y-axis for a < var < b, when [a,b] is cut into n equal parts, along with the graph in red.

Examples.

• Input:
plotarea(sin(x),x=0..2*pi)
Output:
• Input:
plotarea(x^2,x=0..1,5,trapezoid)
Output:
Input:
plotarea((x^2,x=0..1,5,middle_point)
Output:

## 8.11  Contour lines: plotcontourcontourplotDrwCtour

The plotcontour command draws contour lines for functions of two variables.
DrwCtour and contourplot are synonyms for plotcontour.

• plotcontour takes two mandatory arguments and one optional argument:
• expr, an expression involving two variables.
• vars, a list of the two variables.
• Optionally, values, a list of values of the contour lines to draw; expr=value, for value in values (by default, [−10,−8,…,8,10]).
• plotcontour(expr,vars ⟨, values) draws the contour lines expr=value for value in values.

Examples.

• Input:
plotcontour(x^2+y^2,[x=-3..3,y=-3..3],[1,2,3], display=[green,red,black]+[filled\$3])
Output:
• Input:
plotcontour(x^2-y^2,[x,y])
Output:

If you want to draw the surface in 3-d representation, you can use plotfunc (see Section 8.4.2).
Input:

plotfunc(x^2-y^2,[x,y])

Output:

## 8.12  2-d graph of a 2-d function with colors: plotdensitydensityplot

The plotdensity command draws the graph of a function of two variables in the plane where the values of z are represented by the rainbow colors.
densityplot is a synonym for plotdensity.

• plotdensity takes two mandatory arguments and three optional arguments:
• expr, an expression of two variables.
• vars, a list of the variables and their ranges.
• Optionally, z=a..b, the range of z to correspond to the full rainbow (by default, it is deduced from the minimum and maximum value of expr on the discretization.
• Optionally, xstep, which can be xstep=n to specify the discretization step in the x direction.
• Optionally, ystep, which can be ystep=m to specify the discretization step in the y direction.
• Instead of xstep and ystep, you could use the option nstep=n to specify the number of points used to graph.
• plotdensity(expr,vars ⟨z=a..b,xstep,ystep) draws the graph of expr in the plane where the values of z are represented by the rainbow colors.

Remark: A rectangle representing the scale of colors will be displayed below the graph.

Example.
Input:

plotdensity(x^2-y^2,[x=-2..2,y=-2..2], xstep=0.1,ystep=0.1)

Output:

## 8.13  Implicit graph: plotimplicitimplicitplot

The plotimplicit command draws curves or surfaces defined by an implicit expression or equation. If the option unfactored is given as the last argument, the original expression is taken unmodified. Otherwise, the expression is normalized, then replaced by the factorization of the numerator of its normalization.

Each factor of the expression corresponds to a component of the implicit curve or surface. For each factor, Xcas tests if it is of total degree less or equal to 2, in which case conic or quadric is called. Otherwise the numeric implicit solver is called.

Optional step and ranges arguments may be passed to the numeric implicit solver, note that they are dismissed for each component that is a conic or a quadric.

implicitplot is a synonym for plotimplicit.

## 8.14  Parametric curves and surfaces: plotparamparamplotDrawParm

The plotparam command draws parametric curves and surfaces.
paramplot and DrawParm are synonyms for plotparam.

## 8.15  Bezier curves: bezier

The Bezier curve with the control points P0,P1,…,Pn is the curve parameterized by ∑j=0n (

 n,j t

)j (1−t)nj Pj. bezier plots Bezier curves.

• bezier takes an unspecified number of arguments:
• controls, a sequence of control points.
• plot, the symbol.
• bezier(controls,plot) plots the Bezier curve with the given control points.

Examples.

• Input:
bezier(1,1+i,2+i,3-i,plot)
Output:
• Input:
bezier(point(0,0,0),point(1,1,0),point(0,1,1),plot)
Output:

To get the parameterization of the curve, you can use the parameq command (see Section 13.13.8).

Examples.

• Input:
parameq(bezier(1,1+i,2+i,3-i))
Output:  ⎛ ⎝ 1−t ⎞ ⎠ 3+3 t ⎛ ⎝ 1−t ⎞ ⎠ 2 ⎛ ⎝ 1+i ⎞ ⎠ +3 t2 ⎛ ⎝ 1−t ⎞ ⎠ ⎛ ⎝ 2+i ⎞ ⎠ +t3 ⎛ ⎝ 3−i ⎞ ⎠
• Input:
parameq(bezier(point([0,0,0]),point([1,1,0]),point([0,1,1])))
Output:  ⎡ ⎣ 2 t ⎛ ⎝ 1−t ⎞ ⎠ ,2 t ⎛ ⎝ 1−t ⎞ ⎠ +t2,t2 ⎤ ⎦

## 8.16  Defining curves in polar coordinates: plotpolarpolarplotDrawPolcourbe_polaire

The plotpolar command draws a curve given in polar coordinates.
polarplot, DrawPol and courbe_polaire are synonyms for plotpolar.

• polarplot takes two arguments:
• expr, an expression involving a variable (which will represent the angle).
• var, the variable. This can optionally include the range var=a..b.
• Optionally, tstep=n to specify the discretization.
polarplot(expr,var ⟨,tstep=n) draws the curve defined by ρ=expr for θ=var; in Cartesian coordinates that is the curve (expr cosvar),expr sin(var)).

Examples.

• Input
plotpolar(t,t)
Output:
• Input:
plotpolar(t,t,tstep=1)
or:
plotpolar(t,t=0..10,tstep=1)
Output:

## 8.17  Graphing recurrent sequences: plotseqseqplotgraphe_suite

The plotseq command draws the process of finding the terms of a recurrent sequence.
seqplot and graphe_suite are synonyms for plotseq.

• plotseq takes :
• expr, an expression depending on a variable.
• var=a, the variable and a beginning value. (If var=x, then the variable name can be omitted.) The a value can be replaced by a list of three elements, [a,x,x+] where x..x+ will be passed as the range of the variable for the graph computation.
• n, the ending value of the variable.
• plotseq(expr,var=a,n) draws the line y=x, the graph of y=expr, and the n first terms of the recurrent sequence defined by: u0=a, un=f(un−1) where f is the function determined by expr.

Example.
Input:

plotseq(sqrt(1+x),x=[3,0,5],5)

Output:

## 8.18  Tangent field: plotfieldfieldplot

The plotfield command draws the tangent field of a differential equation or a vector field.
fieldplot is a synonym for plotfield.

To draw the tangent field of a differential equation:

• plotfield takes two mandatory arguments and one optional argument:
• expr, an expression depending on two variables, a time variable and a dependent variable.
• vars, a list of the two variables [t,y], where t is the time variable and y is the dependent variable. The variables can optionally include their ranges; [t=a..b,y=c..d].
• Optionally, ystep=n to specify the discretization.
• plotfield(expr,vars ⟨,ystep=n) draws the tangent field of the differential equation y′=f(t,y).

Example.
Input:

plotfield(4*sin(t*y),[t=0..2,y=-3..7])

Output:

To draw a vector field:

• plotfield takes two mandatory arguments and two optional arguments:
• V, a list of two expressions involving two variables.
• vars, a list of the two variables. The variables can optionally include their ranges var=a..b.
• Optionally, xstep=n to specify the discretization of the first variable.
• Optionally, ystep=m to specify the discretization of the second variable.
• plotfield(V,vars ⟨ ,xstep=n,ystep=m) draws the vector field given by V.

Example.
Input:

plotfield(5*[-y,x],[x=-1..1,y=-1..1])

Output:

## 8.19  Plotting a solution of a differential equation: plotodeodeplot

The plotode command draws solutions of differential equations.

• plotode takes three mandatory arguments and one optional argument:
• expr an expression depending on two or three variables, a time variable and one or two dependent variables.
• vars, a list of the time variable and the dependent variable. The time variable can optionally have a range of values, such as t=a..b. The dependent variable can also be a vector of size two.
• init, the initial values of the variables.
• Optionally, for when there are two dependent variables, plane, the symbol, to draw the solution in the plane.
• plotode(expr,vars,init) draws the solution of the differential equation y′=expr (where y is the dependent variable) passing through the initial point init.

To compute the values of the solutions, see Section 10.3.5.

Examples.

• Input:
plotode(sin(t*y),[t,y],[0,1])
Output:
• Input:
S:=plotode([h-0.3*h*p, 0.3*h*p-p], [t,h,p],[0,0.3,0.7])
Output:
• Input (for a 2-d graph in the plane):
S:=odeplot([h-0.3*h*p, 0.3*h*p-p], [t,h,p],[0,0.3,0.7],plane)
Output:

## 8.20  Interactive plotting of solutions of a differential equation: interactive_plotodeinteractive_odeplot

The interactive_plotode command draws interactive tangent fields of differential equations.
interactive_odeplot is a synonym for interactive_plotode.

• interactive_plotode takes two arguments:
• expr an expression depending on two or three variables, a time variable and one or two dependent variables.
• vars, a list of the time variable and the dependent variable.
• interactive_plotode(expr,vars) draws the tangent field of the differential equation y′=expr (where y is the dependent variable) in a new window. In this window, one can click on a point to get the plot of the solution of y′=expr passing through this point.

You can further click to display several solutions. To stop, press the Esc key.

Example.
Input:

interactive_plotode(sin(t*y),[t,y])

Output:

Solutions of the differential equation can be plotted by clicking on an initial point.

## 8.21  Animated graphs (2D, 3D or "4D")

Xcas can display animated 2D, 3D or "4D" graphs. This is done first by computing a sequence of graphic objects, then after completion, by displaying the sequence in a loop. To stop or start again the animation, click on the button ▸ ∣ (to the left of Menu).

• # Chapter 9  Statistics

## 9.1  One variable statistics

Xcas has several functions to perform statistics; the data is typically given as a list of numbers, such as A:= [0,1,2,3,4,5,6,7,8,9,10,11]. This particular list will be used in several examples. Section 6.45.16 will discuss statistics on matrices.

# Chapter 10  Numerical computations

Real numbers may have an exact representation (e.g. rationals, symbolic expressions involving square roots or constants like π, …) or approximate representation, which means that internally the real is represented by a rational (with a denominator that is a power of the basis of the representation) close to the real. Inside Xcas, the standard scientific notation is used for approximate representation; that is a mantissa (with a point as decimal separator) optionally followed by the letter e and an integer exponent.

Note that the real number 10−4 is an exact number but 1e−4 is an approximate representation of this number.

## 10.1  Floating point representation.

This section discusses how real numbers are represented.

## 10.2  Approximate evaluation: evalfapproxDigits

The evalf command evalf or approx, if possible, evaluates to a numeric approximation (see Section 6.8.1). The approximation is to Digits digits (see Section 3.5.1), this can be changed with an optional second argument.

Examples.

• Input:
evalf(sqrt(2))
Output: (Assuming that in the cas configuration (Cfg menu) Digits=7, so hardware floats are used, and 7 digits are displayed)  1.41421
• You can change the number of digits in a command line by assigning the variable DIGITS or Digits.
Input:
 DIGITS:=20 evalf(sqrt(2))
Output:  1.41421
• Input:
evalf(10^-5)
Output:  1e-05
• Input:
evalf(10^15)
Output:  1e+15
• Input:
evalf(sqrt(2))*10^-5
Output:  1.41421e-05

## 10.4  Solving equations with fsolvenSolvecfsolve

The fsolve command can solve equations or systems of equations. This section will discuss solving equations; systems will be discussed in the next section.

The cfsolve command is the complex version of fsolve, with the same arguments. The only difference is that cfsolve gives numeric solutions over the complex numbers, even if Xcas is not in complex mode (see Section 3.5.5). fsolve will return complex roots, but only in complex mode.

fsolve solves numeric equations of the form:

 f(x)=0,    x ∈ (a,b)

Unlike solve (Section 6.55.6) or proot (Section 10.6), it is not limited to polynomial equations.
nSolve is a synonym for fsolve.

• fsolve takes one mandatory argument and three optional arguments:
• eqn, an equation involving one variable.
• Optionally, var, the variable (by default x).
• Optionally, init, an initial approximation or range.
• Optionally, algorithm, the name of an iterative algorithm to be used by the GSL solver.
• fsolve(eqn,var,init ⟨,algorithm) returns an approximate solution to the equation.

Examples.

• Input (in real mode):
fsolve(x^3-1,x)
Output:  1
• Input (in complex mode):
fsolve(x^3-1,x)
Output:  ⎡ ⎣ −0.5−0.866025403784i,−0.5+0.866025403784i,1.0 ⎤ ⎦
• Input (in any mode):
cfsolve(x^3-1,x)
Output:  ⎡ ⎣ −0.5−0.866025403784 i,−0.5+0.866025403784 i,1.0 ⎤ ⎦
• Input:
fsolve(sin(x)=2)
Output:  ⎡ ⎣ ⎤ ⎦
• Input:
cfsolve(sin(x)=2)
Output:  ⎡ ⎣ 1.57079632679−1.31695789692 i,1.57079632679+1.31695789692 i ⎤ ⎦

The different values of algorithm are explained in the rest of this section.

## 10.5  Solving systems with fsolve and cfsolve

The previous section discussed using fsolve to solve equations. This section will discuss systems of equations.

As before, the cfsolve command is the complex version of fsolve, with the same arguments. The only difference is that cfsolve gives numeric solutions over the complex numbers, even if Xcas is not in complex mode (see Section 3.5.5). fsolve will return complex roots, but only in complex mode.

For solving systems of equations:

• fsolve takes three mandatory arguments and one optional argument:
• eqns, a list of equations (or expressions, considered to be equal to zero) to solve.
• vars, a list of the variables.
• init, a list initial values for the variables.
• Optionally, method, the method to use. The possible methods are:
• dnewton_solver
• hybrid_solver
• hybrids_solver
• newtonj_solver
• hybridj_solver
• hybridsj_solver
• fsolve(eqns,vars,init ⟨,method) returns an approximate solution to eqns.

Examples.

• Input (in real mode):
fsolve([x^2+y+1,x+y^2-1],[x,y])
Output:

 0.0 −1.0 −0.453397651516 −1.2055694304

• Input (in complex mode):
fsolve([x^2+y+1,x+y^2-1],[x,y])
Output:

 0.0 −1.0 0.226698825758−1.46771150871 i 1.1027847152+0.665456951153 i 0.226698825758+1.46771150871 i 1.1027847152−0.665456951153 i −0.453397651516 −1.2055694304

• Input (in any mode):
cfsolve([x^2+y+1,x+y^2-1],[x,y])
Output:

 0.0 −1.0 0.226698825758−1.46771150871 i 1.1027847152+0.665456951153 i 0.226698825758+1.46771150871 i 1.1027847152−0.665456951153 i −0.453397651516 −1.2055694304

• Input:
cfsolve([x^2+y+2,x+y^2+2],[x,y])
Output:

 0.5+1.65831239518 i 0.5−1.65831239518 i 0.5−1.65831239518 i 0.5+1.65831239518 i −0.5+1.32287565553 i −0.5+1.32287565553 i −0.5−1.32287565553 i −0.5−1.32287565553 i

The methods are inherited from the GSL. The methods whose names end with j_solver use the jacobian matrix, the rest use approximations for the derivatives.

All methods use an iteration of Newton kind

xn+1=xn
 f(xn) f′(xn)

The four methods hybrid*_solver use also a method of gradient descent when the Newton iteration would make a too large of a step. The length of the step is computed without scaling for hybrid_solver and hybridj_solver or with scaling (computed from f′(xn)) for hybrids_solver and hybridsj_solver.

The rest of this section will cover the various method options.

## 10.6  Numeric roots of a polynomial: proot

The proot command numerically finds the roots of a squarefree polynomial.

• proot takes one argument:
P, a squarefree polynomial, either in symbolic form or as a list of polynomial coefficients (written by decreasing order).
• proot(P) returns a list of the numeric roots of P.

Examples.

• Input: Find the numeric roots of P(x)=x3+1:
Input:
proot([1,0,0,1])
or:
proot(x^3+1)
Output:  ⎡ ⎣ −1.0,0.5−0.866025403784 i,0.5+0.866025403784 i ⎤ ⎦
• Find the numeric roots of x2−3:
Input:
proot([1,0,-3])
or:
proot(x^2-3)
Output:  ⎡ ⎣ −1.73205080757,1.73205080757 ⎤ ⎦

## 10.7  Numeric factorization of a matrix: choleskyqrlusvd

Matrix numeric factorizations of

• Cholesky,
• QR,
• LU,
• svd,

are described in Section 6.49.

# Chapter 12  Programming

A program that you write for Xcas might be longer than one line; the first section discusses how you can enter it.

# Chapter 13  Two-dimensional Graphics

## 13.4  Defining geometric objects without drawing them: nodisp

The nodisp command defines an object without displaying it.

• nodisp takes one argument:
command, a command to create an object.
• nodisp(command) creates the object withouth drawing it.

Setting a variable to a graphic object draws the object.

Examples.

• Input:
C:= point(1+i)
Output:
Input:
nodisp(C:= point(1+i))
Here, the point C is defined but not displayed. It is equivalent to following the command with :;,
Input:
C:= point(1+i):;
To define a point as above and display it without the label, enter the point’s name;
Input:
C
Output:
Alternatively, you can get the same effect by defining the point within an eval statement:
Input:
eval(C:= point(1+i))
To later display the point with a label, use the legend command:
Input:
legend(C,"C")
or:
point(affix(C),legend="C")
Output:
In this case, the string "C" can be replaced with any other string as a label. Alternatively, redefine the variable as itself:
Input:
C:= C
prints C with its label.

## 13.5  Geometric demonstrations: assume

Variables should be unspecified to demonstrate a general geometric result, but need to have specific values when drawing. There are a couple of different approaches to deal with this.

One approach is to use the assume command (see Section 5.4.8). If a variable is assumed to have a value, then that value will be used in graphics but the variable will still be unspecified for calculations. For example: Input:

 assume(a = 2.1) A:= point(a + i)

Output:

but the variable a will still be treated as a variable in calculations:
Input:

distance(0,A)

Output:

 ⎛ ⎝ −a ⎞ ⎠ 2+1

Another approach would be to use the point or pointer mode in a geometry screen. If there isn’t a geometry screen showing, the command Alt-G or the GeoNew figure 2d menu will open a screen. Clicking on the Mode button right above the graphic screen and choosing pointer or point will put the screen in pointer or point mode. If a point is defined and displayed, such as with A:= point(2.1 + i), then clicking on the name of the point (A in this case) with the right mouse button will bring up a configuration screen. As long as there is a point defined with non-symbolic values, there will be a symb box on the configuration screen. Selecting the symb box and choosing OK will be equivalent to the commands:

 assume(Ax=[2.1,-8.16901408451,8.16901408451]) assume(Ay = [1, -5.0, 5.0]

This will bring up two lines beneath the arrows to the right of the screen which can be used to change the assumed values of Ax and Ay. Also, the point A will be redefined as point(Ax,Ay).

## 13.8  Triangles in the plane

See Section 14.7 for triangles in space.

## 13.9  Quadrilaterals in the plane

See Section 14.8 for quadrilaterals in space.

## 13.10  Other polygons in the plane

See Section 14.9 for polygons in space.

# Chapter 14  Three-dimensional Graphics

## 14.1  Introduction

The Alt+H command brings up a display screen for three-dimensional graphics. This screen has its own menu and command lines.

This screen also automatically appears whenever there is a three-dimensional graphic command.

The plane of vision for a three-dimensional graphic screen is perpendicular to the observer’s line of vision. The plane of vision is also indicated by dotted lines showing its intersection with the parallelepiped. The axis of vision for a three-dimensional graphic screen is

The three-dimensional graphic screen starts with the image of a parallelepiped bounding the graphics and vectors in the x, y and z directions. At the top of the screen is the equation of the plane of vision, which is a plane perpendicular to the observer’s line of vision. The plane of vision is shown graphically with dotted lines indicating where it intersects the plane of vision.

Clicking in the graphic screen outside of the parallelepiped and dragging the mouse moves the x, y and z directions relative to the observer; these directions are also changed with the x, X, y, Y, z and Z keys. Scrolling the mouse wheel moves the plane of vision along the line of vision. The in and out buttons on the graphic screen menu zoom in and out of the picture.

The graphical features available for two-dimensional graphics (see Section 13.3) are also available for three-dimensional graphics, but to see the points the markers must be squares with width (point_width) at least 3.

The graphic screen menu has a cfg button which brings up a configuration screen. Among other things, this screen has

• An Ortho proj button, which determines whether the drawing uses orthogonal projection or perspective projection.
• A Lights button, which determines whether the objects are lit or not; the locations of eight points for lighting are set using the buttons L1, …, L7, which specify the points with homogeneous coordinates.
• A Show axis button, which determines whether or not the outlining parallelepiped is visible.

## 14.2  Changing the view

The depictions of three-dimensional objects are made with a coordinate system Oxyz, where the x axis is horizontal and directed right, the y axis is vertical and directed up, and the z axis is perpendicular to the screen and directed out of the screen. The depictions can be transformed by changing to a different coordinate system by setting a quaternion (see Section 13.3.2).

## 14.6  Planes in space

See also sections 14.5.6 and 14.5.7 for planes perpendicular and orthogonal to lines and planes.

## 14.7  Triangles in space

See Section 13.9 for quadrilaterals in the plane.

## 14.9  Polygons in space

See Section 13.10 for polygons in the plane.

## 14.10  Circles in space: circle

See Section 13.11.1 for circles in the plane.

The circle command returns and draws a circle. It can take its arguments in various ways.

Three points.

• circle takes three arguments:
A,B,C, three points.
• circle(A,B,C) returns and draws the circle in plane ABC with a diameter AB.

Example.
Input:

circle(point(0,0,1),point(0,1,0),point(0,2,2))

Output:

Two points and a vector.

• circle takes three points:
• C, a point (which can be given by its coordinates).
• v, a vector.
• A, a point (which can be given by its coordinates).
• circle(C,v,A) returns and draws the circle in plane C(C+v)C with center C and containing C+v.

Example.
Input:

circle(point(0,0,1),vector(0,1,0),point(0,2,2))

Output:

## 14.17  Platonic solids

To specify a Platonic solid, Xcas works with the center, a vertex and a third point to specify a plane of symmetry. To speed up calculations, it may be useful to use approximate calculations, which can be ensured with the evalf command. For example, instead of:
Input:

centered_cube([0,0,0],[3,2,1],[1,1,0])

it would typically be better to use:
Input:

centered_cube(evalf([0,0,0],[3,2,1],[1,1,0]))

# Chapter 15  Multimedia

## 15.1  Audio Tools

Xcas has commands for working with audio objects. An audio object is a vector consisting of:

• The first element is itself a list consisting of:
• The number of channels (generally 1 for mono and 2 for stereo).
• The number of bits (generally 16).
• The sampling frequency (44100 for a CD quality sound).
• The number of bytes (excluding the header); i.e., the number of seconds times the sampling frequency times the number of bits/8 times the number of channels.
• The second element is another list of digital sound data for each channel.

Xcas can read and write audio objects as files on your computer; these files will be in the wav (Waveform Audio File) format.

For creating and playing audio objects, there are:

• createwav, for creating audio objects (see Section 15.1.1).
• playsnd, for playing audio objects (see Section 15.1.4).

For reading and writing audio files, there are:

• readwav, for reading audio files from disk and creating audio objects (see Section 15.1.2).
• writewav, for writing audio files to disk from audio objects (see Section 15.1.3).

For manipulating audio objects, there are:

• stereo2mono, to convert a multichannel audio clip to a single channel (see Section 15.1.5).
• resample, to change the sample rate (see Section 15.1.8).

For getting information from an audio object, there are:

• channels, to find the number of channels (see Section 15.1.6).
• bit_depth, to find the number of bits in each sample value (see Section 15.1.6).
• samplerate, to find the number of samples per second (see Section 15.1.6).
• duration, to find the duration of the audio in seconds (see Section 15.1.6).
• channel_data, to extract a sample from an audio (see Section 15.1.7).
• plotwav, to visualize a waveform (see Section 15.1.9).
• plotspectrum, to visualize the power spectra (see Section 15.1.10).

# Chapter 16  Using giac inside a program

## 16.1  Using giac inside a C++ program

To use giac inside of a C++ program, put

```  #include <giac/giac.h>
```

at the beginning of the file. To compile the file, use

```  c++ -g progname.cc -lgiac -lgmp
```

After compiling, there will be a file a.out which can be run with the command

```  ./a.out
```

For example, put the following program in a file named pgcd.cc.

```// -*- compile-command: "g++ -g pgcd.cc -lgiac -lgmp" -*-
#include <giac/config.h>
#include <giac/giac.h>

using namespace std; using namespace giac;

gen pgcd(gen a,gen b){ gen q,r; for (;b!=0;){ r=irem(a,b,q); a=b; b=r;
} return a; }

int main(){ cout << "Enter 2 integers "; gen a,b; cin >> a >> b; cout
<< pgcd(a,b) << endl; return 0; }
```

After compiling this with

```  c++ -g pgcd.cc -lgiac -lgmp
```

and running it with

```  ./a.out
```

there will be a prompt

```  Enter 2 integers
```

After entering two integers, such as with

```  Enter 2 integers  30 36
```

the result will appear:

```  6
```

## 16.2  Defining new giac functions

New giac functions can be defined with a C++ program. All data in the program used in formal calculations needs to be gen type. A variable g can be declared to be gen type with

```  gen g;
```

In this case, g.type can have different values.

• If g.val is an integer type int, then g.type will be _INT_.
• If g._DOUBLE_val is a real double, g.type will be _DOUBLE_.
• If g._SYMBptr is type symbolic, then g.type will be _SYMB.
• If g._VECTptr is a vector, type vector, then g.type will be _VECT.
• If g._ZINTptr is an integer type zint, then g.type will be _ZINT.
• If g._IDNTptr is an identifier, type idnt, then g.type will be _IDNT.
• If g._CPLXptr is a complex type complex, then g.type will be _CPLX.

As an example, put the following program in a file called pgcd.cpp.

```// -*- mode:C++ ; compile-command: "g++ -I.. -fPIC -DPIC -g -c pgcd.cpp -o pgcd.lo && \
//    ln -sf pgcd.lo pgcd.o && \
//    gcc -shared pgcd.lo -lc -lgiac -Wl,-soname -Wl,libpgcd.so.0 -o \
//    libpgcd.so.0.0.0 && ln -sf libpgcd.so.0.0.0 libpgcd.so.0 && \
//    ln -sf libpgcd.so.0.0.0 libpgcd.so" -*-
using namespace std;
#include <stdexcept>
#include <cmath>
#include <cstdlib>
#include <giac/config.h>
#include <giac/giac.h>
//#include "pgcd.h"

#ifndef NO_NAMESPACE_GIAC namespace giac { #endif // ndef
NO_NAMESPACE_GIAC

gen monpgcd(const gen & a0,const gen & b0){ gen q,r,a=a0,b=b0; for
(;b!=0;){ r=irem(a,b,q); a=b; b=r; } return a; } gen _monpgcd(const
gen & args,GIAC_CONTEXT){ if ( (args.type!=_VECT) ||
(args._VECTptr->size()!=2)) setsizeerr(); vecteur &v=*args._VECTptr;
return monpgcd(v[0],v[1]); } const string _monpgcd_s("monpgcd");
unary_function_eval __monpgcd(0,&_monpgcd,_monpgcd_s);
unary_function_ptr at_monpgcd (&__monpgcd,0,true);

#ifndef NO_NAMESPACE_GIAC } // namespace giac #endif // ndef
NO_NAMESPACE_GIAC
```

After compiling this with the commands after the compile-command in the header, namely

```  g++ -I.. -fPIC -DPIC -g -c pgcd.cpp -o pgcd.lo && \
ln -sf pgcd.lo pgcd.o && \
gcc -shared pgcd.lo -lc -lgiac -Wl,-soname -Wl,libpgcd.so.0 -o \
libpgcd.so.0.0.0 && ln -sf libpgcd.so.0.0.0 libpgcd.so.0 && \
ln -sf libpgcd.so.0.0.0 libpgcd.so
```

the new command can be inserted with the insmod command in giac, where insmod takes the full absolute path of the libpgcd.so file as argument.
Input:

insmod("/path/to/file/libpgcd.so")

Afterwords, the monpgcd command will be another giac command.
Input:

monpgcd(30,36)

Output:

 6

1
Université de Grenoble, initial translation of parts of the French user manual
2
Full translation and improvements
3
Optimization, signal processing. The graph theory is in a separate manual.

This document was translated from LATEX by HEVEA.