Symbolic algebra and Mathematics with XcasRenée De Graeve, Bernard Parisse1, |
© 2002, 2007 Renée De Graeve, Bernard Parisse
renee.degraeve@wanadoo.fr
bernard.parisse@ujf-grenoble.fr
|
|
In this manual, the information that you enter will be typeset in typewriter font. User input typically takes one of three forms:
The index will use different typefaces for different parts of the language. The commands themselves will be written with normal characters, command options will be written in italics and values of commands or options will be written in typewriter font. For example (as you will see later), you can draw a blue parabola with the command
In the index, you will see
The giac library is a C++ mathematics library. It comes with two interfaces for users to use it directly; a graphical interface and a command-line interface.
The graphical interface is called Xcas, and is the most full-featured interface. As well being able to do symbolic and numeric calculations, it has its own programming language, it can draw graphs, it has a built-in spreadsheet, it can do dynamic geometry and turtle graphics.
The command-line interface can be run inside a terminal. It can also do symbolic and numeric calculations and works with the programming language. In a graphical environment, the command-line interface can also be used to draw graphs.
There is also a web version, which can be run through a browser, either over the internet or from local files. Other programs (for example, TeXmacs) have interfaces for the command-line version.
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 input level. Each level can have one of the following:
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 is an expression editor. 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 allowing you to manipulate the graphic.
Using commands discussed later, different types of levels can be combined to form a single hybrid level. Levels can also be moved up or 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.
A level can be selected (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 will turn 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.
When you first start Xcas, you will be given a largely blank window.
The first row will be 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 be tabs; one tab for each session that you are running in Xcas. The tabs will contain the name of the sessions, or Unnamed if a session has no name. The first time you start Xcas, there will be only one unnamed session.
The third row will contain various buttons.
The << and >> buttons will scroll through menu items. Clicking on one of the menu buttons will perform the appropriate action or replace the menu items by 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 will replace the menu buttons by buttons representing the variables that you have defined. After that is a cust button, which will display commands that you store in a list variable CST (see section ??).
The last button, X, will close the menu bar.
Xcas is an extensive program, but you can get help in several different ways. The help menu (see section 3.4.4) has several submenus for various forms of help, some of which are mentioned below.
Xcas can translate a session, or parts of a session, to other computer languages; notably LATEX and MathML.
If you enter a command into Xcas, the result will appear in the output box below the input. If you enter
then
will appear in the output box. You can evaluate the input and suppress the output with the nodisp command. If you enter
then a will still be set to 4, but the result will not appear in the output box. Instead,
will appear.
An alternate way of suppressing the output is to end the input with :;, if you enter
then b will be set to 6 but it won’t be displayed.
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 begun entering a command when you begin a comment, the command line be pushed down so that you can finish it when you complete the comment.
You can open the browser in a comment line by entering the web address beginning with the @ sign. If you enter the comment line
then the browser will open to the Xcas home page.
To add a comment to a program, rather than a session, you can use the comment command, which takes a string as an argument. Alternatively, any part of a program between // and the end of the line is a comment. So both
and
are programs with the comment "Hello".
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.
The ans command will return the results of previous commands. The input to ans is the number of the command, beginning with 0. If the first command that you enter is
resulting in
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() wil also return the latest output.
Similarly, quest will return 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 Ctrl+downarrow will go forwards.
e (or %e) is the number exp(1);
pi (or %pi) is the number π.
infinity is unsigned ∞.
+infinity or inf is +∞.
-infinity or -inf is −∞.
i (or %i) is the complex number i.
euler_gamma is Euler’s constant γ; namely,
limit(sum(1/k,k,1,n)-ln(n),n,+infinity)
convert or convertir can do different kind of conversions depending on the option given as the second argument.
To convert an integer n into the list of its coefficients in
base b, the option is base. The arguments of convert or
convertir are an integer n, base and b, the value of the
basis.
convert or convertir returns the list of coefficients in a b
basis of the integer n.
Input :
Output :
To check the answer,
input expr("0173") or horner(revlist([3,7,1]),8)
or convert([3,7,1],base,8), the output is 123
Input :
Output :
To convert the list of coefficients of an integer n in base b,
the option is also base.
convert or convertir returns the integer n.
Input :
or :
Output :
Input :
or :
Output :
For all functions in this section, you can use Gaussian integers (numbers of the form a+ib, where a and b are in ℤ) in place of integers.
A permutation p of size n is a bijection from [0..n−1] on
[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 application from [0,1,2,3] on [0,1,2,3] defined by :
p(0)=1, p(1)=3, p(2)=2, p(3)=0 |
A cycle c of size p is represented by the list [a0,...,ap−1] (0≤ ak≤ n−1) it is the permutation such that
c(ai)=ai+1 for (i=0..p−2), c(ap−1)=a0, c(k)=k otherwise |
A cycle c is represented by a list and a cycle decomposition
is represented by a list of lists.
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]).
Note that complex numbers are also used to represent a point in the plane or a 1-d function graph.
An operator is an infixed function.
Polynomials are represented by expressions or by list of coefficients by 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 modular coefficients in ℤ/nℤ, use % n for each coefficient of the list or apply it to the expression defining the polynomial.
The way to compute over ℤ/pℤ or over ℤ/pℤ[x] depends on the syntax mode :
^
2+3*x-1)%13 or ^
2+3%13*x-1%13.
Remark
The functions described here may be used if the statistics series is contained in a list. See also section 5.49.32 for matrices.
^
2=size(l)*stddev(l)^
2/(size(l)-1).
Example
Define the list A by:
Outputs :
A table is an associative container (or map), it is used to store information
associated to indexes which are much more general than integers,
like strings or sequences. It may be used for example to store
a table of phone numbers indexed by names.
In Xcas, the indexes 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.)
table takes as argument a list or a sequence of equalities
index_name=element_value.
table returns this table.
Input :
Input :
Output :
Input :
Output :
Remark
If you assign T[n]:= ... where T is a variable name
and n an integer
A matrix is represented by a list of lists, all having the same size.
In the Xcas answers, the matrix delimiters are [] (bold brackets).
For example, [1,2,3] is the matrix [[1,2,3]] with only one row,
unlike [1,2,3] (normal brackets) which is the list [1,2,3].
In this document, the input notation ([[1,2,3]]) will be used for input
and output.
Linear programming problems are maximization problem of a linear functionals under linear equality or inequality constraints. The most simple case can be solved directly by the so-called simplex algorithm. Most cases require to solve an auxiliary linear programming problem to find an initial vertex for the simplex algorithm.
See section 5.44.1 for different norms on vectors.
Note that most matrix factorization algorithms are implemented numerically, only a few of them will work symbolically.
In this paragraph, we call the "augmented matrix" of the system A · X=B (or matrix "representing" the system A · X=B), the matrix obtained by gluing the column vector B or −B to the right of the matrix A, as with border(A,tran(B)).
This section is limited to symbolic (or exact) solutions of differential equations. For numeric solutions of differential equations, see odesolve. For graphic representation of solutions of differential equations, see plotfield, plotode and interactive_plotode.
The dayofweek command takes as arguments three integers; the
first represents the day of the month, the second the month, and the
third the year. The resulting date should be after 15 October 1582.
dayofweek returns an integer from 0 to 6; 0 represents a
Sunday, 1 represents Monday, etc.
Input:
Output:
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, which kept years for every year divisible by 4, except if a year is divisible by 100 but not 400 it is not a leap year. 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.
Input:
Output:
This means that 1 October, 2014 was a Wednesday.
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).
The curvature command takes two arguments and an optional
third argument. The first
argument is a curve, and the second argument is a point on the curve.
If the curve is given by a parameterization, the second argument is the
parameter, and an optional third argument is a value of the parameter.
curvature returns the curvature of the curve at
the given point.
Input:
Output:
Input:
Output:
Input:
Output:
The osculating_circle command takes two or three arguments.
The arguments can be either a curve in the plane and a point on the
curve, or the parameterization of a curve in the plane, the parameter,
and a value of the parameter.
osculating_circle returns and draws the osculating circle.
Input:
Output:
Input:
Output:
Input:
Output:
The evolute command takes one or two arguments.
The arguments can be either a curve in the plane, or
the parameterization of a curve in the plane and the parameter.
evolute draws and returns the evolute of the curve.
Input:
Output:
Input:
Output:
Input:
Output:
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.
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, with
Input:
Input:
will both produce the same graph. However, here the graphic
G won’t be reusable. Entering
Input:
reproduces the graph, but entering
Input:
produces the error
Output:
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).
A graphic screen, either two- or three-dimensional as appropriate, automatically opens in response to a graphic command. Alternatively, a graphic screen with its own command line will open 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.
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.
There are two kinds of attributes: global attributes of a graphic scene and individual attributes.
plot(f(x),x) draws the graph of y=f(x).
The second argument may specify the range of values x=xmin..xmax. One can also plot a function instead of an
expression using the syntax plot(f,xmin..xmax).
plot accepts an optional argument to specify
the step used in x for the discretization with
xstep=
or the number of points of the discretization
with nstep=
.
Input :
^
2-2,x)Output :
^
2-2Input :
^
2-2,xstep=1)or :
^
2-2,x,xstep=1)Output :
^
2-2 Input!
^
2-2,x=-2..3,nstep=30)
plot3d takes three arguments : a function of two variables or
an expression of two variables or a list of three functions of two variables
or a list of three expressions of two variables and the names of these two
variables with an optional range (for expressions) or the ranges
(for functions).
plot3d(f(x,y),x,y) (resp. plot3d([f(u,v),g(u,v),h(u,v)],u,v)) draws
the surface z=f(x,y) (resp. x=f(u,v),y=g(u,v),z=h(u,v)).
The syntax plot3d(f(x,y),x=x0..x1,y=y0..y1) or
plot3d(f,x0..x1,y0..y1) specifies which part of surface
will be computed (otherwise default values are taken from the graph
configuration).
Input :
Output :
Input :
Output :
Input :
Output :
plotinequation([f1(x,y)<a1,...fk(x,y)<ak],[x=x1..x2,y=y1..y2]) draws the points of the plane whose coordinates satisfy the inequalities of 2 variables :
⎧ ⎪ ⎨ ⎪ ⎩ |
| , x1≤ x ≤ x2, y1 ≤ y ≤ y2 |
Input :
^
2-y^
2<3, [x=-2..2,y=-2..2],xstep=0.1,ystep=0.1)Output :
^
2-y^
2=3Input :
^
2<y], [x-2..2,y=-1..10],xstep=0.2,ystep=0.2)Output :
^
2Note that if the ranges for x and y are not specified, Xcas takes the default values of X-,X+,Y-,Y+ defined in the general graphic configuration (Cfg▸Graphic configuration).
The area command takes four arguments; an expression f(x), a range for the variable x=a..b, an integer n, and the name of the approximation method. The approximation method can be one of
area 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).
Input:
Output:
Input:
Output:
Input:
Output:
Input:
Output:
^
2,x=0..1,5,trapezoid)^
2,x=0..1,5,trapezoid);
plot(x^
2,x=0..1,display=red+line_width_3)^
2,x=0..1,5,middle_point)^
2,x=0..1,5,middle_point); plot(x^
2,x=0..1,display=red+line_width_3)
plotcontour(f(x,y),[x,y]) (or DrwCtour(f(x,y),[x,y]) or
contourplot(f(x,y),[x,y]))
draws the contour lines of the surface defined by z=f(x,y) for z=−10,
z=−8, .., z=0, z=2, .., z=10. You may specify the desired contour
lines by a list of values of z given as third argument.
Input :
^
2+y^
2,[x=-3..3,y=-3..3],[1,2,3], display=[green,red,black]+[filled$3])Output :
^
2-y^
2=n for n=1,2,3; the zones between these ellipses are filled with the color green,red or blackInput :
^
2-y^
2,[x,y])Output :
^
2-y^
2=n for n=-10,-8,..10If you want to draw the surface in 3-d representation, input plotfunc(f(x,y),[x,y]), see 7.4.2):
^
2-y^
2,[x,y])Output :
^
2+y^
2
plotdensity(f(x,y),[x,y]) or densityplot(f(x,y),[x,y])
draws the graph of z=f(x,y) in the plane where the values of
z are represented by the rainbow colors. The optional argument
z=zmin..zmax specifies the range of z corresponding to the
full rainbow, if it is not specified, it is deduced from the minimum
and maximum value of f on the discretization. The discretization
may be specified by optional xstep=... and ystep=...
or nstep=... arguments.
Input :
^
2-y^
2,[x=-2..2,y=-2..2], xstep=0.1,ystep=0.1)Output :
^
2-y^
2=z has a color from the rainbowRemark : A rectangle representing the scale of colors is displayed below the graph.
plotimplicit or implicitplot draws curves or surfaces defined by an implicit expression or equation. If the option unfactored is given as 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 that 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.
The bezier command takes as argument a sequence L of
points.
bezier(L,plot) plots the Bezier curve with the given control
points.
If the points are P0,P1,…,Pn, the Bezier curve is the curve parameterized by ∑j=0n (
n,j |
t |
)j (1−t)n−j Pj.
Input:
Output:
Input:
Output:
To get the parameterization of the curve, you can use parameq.
Input:
Output:
Input:
Output:
Let Et be an expression depending on the variable t.
plotpolar(Et,t) draws the polar representation of the
curve defined by ρ=Et for θ=t, that is
in cartesian coordinates the curve (Et cos(t),Et sin(t)).
The range of the parameter may be specified by replacing the second argument
by t=tmin..tmax. The discretization parameter may be specified
by an optional tstep=... argument.
Input
Output :
Input
or :
Output :
Let f(x) be an expression depending on the variable x
(resp. f(t) an expression depending on the variable t).
plotseq(f(x),a,n) (resp. plotseq(f(t),t=a,n)) draws the line
y=x, the graph of y=f(x) (resp. y=f(t)) and the n first terms of the
recurrent sequence defined by : u0=a, un=f(un−1).
The a value may be replaced by a list of 3 elements, [a,x−,x+]
where x−..x+ will be passed as x range for the graph computation.
Input :
Output :
Input :
Output :
With two variables x,y, input :
Let f(t,y) be an expression depending on two variables t and y.
Input :
Output :
Input :
Output, the graph in the space of the solution of :
[h,p]′=[h−0.3 h*p, 0.3 h*p−p] [h,p](0)=[0.3,0.7] |
To have a 2-d graph (in the plane), use the option plane
To compute the values of the solution, see the subsection 9.3.5.
Let f(t,y) be an expression depending on two
variables t and y.
interactive_plotode(f(t,y),[t,y]) draws the tangent field
of the differential equation y′=f(t,y) in a new window.
In this window, one can click on a point to get the
plot of the solution of y′=f(t,y) crossing through this point.
You can further click to display
several solutions. To stop press
the Esc key.
Input :
Output :
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.
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]. We will use this particular list in several examples. Section 5.49.32 will discuss statistics on matrices.
Real numbers may have an exact representation (e.g. rationals, symbolic expressions involving square roots or constants like π, ...) or approximate representation, which means that 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.
In this section, we explain how real numbers are represented.
evalf or approx evaluates to a numeric
approximation (if possible).
Input :
Output, if in the cas configuration (Cfg menu) Digits=7 (that is hardware floats are used, and 7 digits are displayed) :
You can change the number of digits in a command line by assigning the variable DIGITS or Digits. Input :
Output :
Input :
^
-5)Output :
Input :
^
15)Output :
Input :
^
-5Output :
fsolve or nSolve solves numeric equations (unlike solve or proot, it is not limited to polynomial equations) of the form:
f(x)=0, x ∈ ]a,b[ |
fsolve or nSolve accepts a last optional argument, the name of an iterative algorithm to be used by the GSL solver. The different methods are explained in the following section.
Xcas provides six methods (inherited from the GSL) to solve numeric systems of equations of the form f(x)=0:
All methods use an iteration of Newton kind
xn+1=xn−f′(xn)−1*f(xn) |
The four methods hybrid*_solver use also a method of gradient descent when the Newton iteration would make a too large 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 cfsolve command gives numeric solutions to an equation or
system over the complex numbers, even if Complex is not
checked in the configuration screen. (The fsolve command
will return complex roots, but Complex needs to be checked in
the configuration screen.)
Input:
Output:
Input:
Output:
proot takes as argument a squarefree polynomial,
either in symbolic form or as a list of
polynomial coefficients (written by decreasing order).
proot returns a list of the numeric roots of this polynomial.
To find the numeric roots of P(x)=x3+1, input :
or :
^
3+1) Output :
To find the numeric roots of x2−3, input :
or :
^
2-3)Output :
Matrix numeric factorizations of
are described in section 5.57.
The nodisp command will define an object without displaying
it. Setting a variable to a graphic object draws the object.
Input:
will define the point C as well as draw it. Setting a
variable to a graphic object inside the nodisp command will
not draw the object.
Input:
will define the point C but not display it. This is
equivalent to following the command with :;,
Input:
To define a point as above and display it without the
label, enter the point’s name;
Input:
Alternatively, define the point within an
eval statement;
Input:
defines C as the point, displays the point, but doesn’t display the
label. To later display the point with a label, use the
legend command.
Input:
or:
Output:
In this case, the string "C" can be replaced with any other string
as a label. Alternatively, redefine the
variable as itself;
Input:
prints C with its label.
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. 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:
then
Input:
will draw a point at the coordinate (2.1,1),
Output:
but the variable a will still be treated as a variable in
calculations;
Input:
Output:
Another approach would be to use point or pointer mode in a geometry screen. If there isn’t a geometry screen showing, the command Alt-G or the Geo▸New 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]) and 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).
See section 13.7 for triangles in space.
See section 13.8 for quadrilaterals in space.
See section 13.9 for polygons in space.
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 12.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
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 12.3.2.)
See also sections 13.5.6 and 13.5.7 for planes perpendicular and orthogonal to lines and planes.
See section 12.9 for quadrilaterals in the plane.
See section 12.10 for polygons in the plane.
See section 12.11.1 for circles in the plane.
The circle command returns and draws a circle.
circle takes as arguments one of the following:
In both cases, the first and third arguments can be the coordinates of the point.
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:
it would typically be better to use:
Input:
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
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.
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:
Afterwords, the monpgcd command will be another giac
command.
Input:
Output:
This document was translated from LATEX by HEVEA.