Skip to main content

Basic Guide - Wiris CAS

Caution

Until now, Wiris CAS was the tool for writing the algorithms in WirisQuizzes Studio Now, as a beta version, you can try CalcMe our cross-browser compatible Javascript calculator, within WirisQuizzes. Find out how hereCalcMe integration in WirisQuizzes Studio.

On this page, you will know the basics of Wiris CAS We will explore random number generation, polynomials and general expressions, and how vectors and matrices work. Some helpful tips about lists comprehension will be given before some basics about geometry features are shown. We will visit some statistical functions, user functions and programming commands. Finally, a detailed explanation of the graphics is given.

Randomness

The random function in WirisQuizzes is adaptable to many use cases. For example, we'll show you how to remove the "0" from a random selection. The standard command would be something like:

rwz_ex1.1.png

By default, this includes all of the numbers between -10 and 10. If the number 0 supposes some sort of difficulty or wrong behaviour for our question, we can remove it with the simple instruction:

rwz_ex1.2.png

We have to add brackets around the first list for this to work. As you may suspect, this can work for any other number we use instead of zero:

rwz_ex1.3.png

The above would produce a random number between -10 and 10, except the number 8. Or you can even do this with more than one number:

rwz_ex1.4.png

This would remove 8,-8, and 0 from the selection. As can be seen, we have many more options than it seems at first when creating a random variable.

So far, we have retrieved integer numbers. We can also obtain real numbers.

random_real.png

Polynomials and expressions

Polynomials are created with numbers times a power of a variable.

polynomials_constructor.png

We can sum, multiply, divide and, for instance, find roots of polynomials.

polynomials_operations.png

We can create more complex expressions and operate with them.

expressions.png

Vector and Matrix constructor

Vectors

Vectors are constructed with square brackets [], and commas , separate the elements.

vector_constructor.png

We can sum vectors or compute the scalar product between them.

vector_operations.png

Matrices

Matrices are vectors of vectors, that is, vectors whose rows are vectors. We can create matrices with two different syntaxes.

matrix_constructor.png

As vectors, we can sum and multiply matrices (as long as dimensions match).

matrix_operations.png

Element access

We can access a specific a vector element using subindices that start on 1. In the same way, we can retrieve an element of a matrix.

basic_guide_elementsaccess.png

Creating lists via comprehension

This section is a short guide to creating lists in WirisQuizzes algorithms, using the commands with and where. This method of defining lists is based on the standard mathematical notation of "set comprehension" or "set-builder notation", for instance:

(x,y)2x0,y0

We'll explain the commands through the following examples.

Example 1

At the most basic level, with provides a more compact form of writing long lists. We could write

lc_ex1.1.png

or we could greatly simplify it to the following:

lc_ex1.2.png

The command where comes in when we want additional restrictions. To get only the even numbers, for example:

lc_ex1.3.png

Alternatively, we could, of course, have gone with:

lc_ex1.4.png

Example 2

In the first example, the size of the list was fixed. However, comprehension shows its most benefit when defining variable-length lists. Here, for example, is a list with random elements of random size.

lc_ex2.1.png

As you may notice, the first expression need not explicitly depend on i i. We can think of i i as just a counter within a specified range. Then, we may or may not use it to define the list elements. It can also be any variable name we choose, as in the following:

lc_ex2.2.png

Example 3

The list comprehension notation can also be extended to more than one variable. In that case, we must specify the range for each variable used as a counter. For example, here is a list with all positive proper fractions in simplest terms, with a single-digit numerator and denominator:

lc_ex3.1.png

Another recommendation illustrated in the above is to enclose each condition after where in parentheses, if we have more than one joined by ,.

Example 4

Finally, we note that the range for the counter variable can itself be a list, defined previously.

lc_ex4.1.png

Example 5

It is also possible to create matrices using this notation. For instance, creating a 4×3 matrix with random coefficients is as simple as this:

lc_ex5.1.png

Geometry

Wiris CAS allows us to deal with geometrical figures such as points, lines, planes and conic sections.

geometry_statement1.png
geometry_plotter1.png

We can also create polygons and polyhedras, both in 2D and 3D.

We can also compute the distance between figures, the angle they form and compute the symmetry.

Statistics

There are a lot of functions involving statistical functions, like mean, quantile, quartile... You can see a complete list here.

cake.png

User functions

We can create our own functions. As you can imagine, the random command is handy, but it could be a bit tedious to write every time random(-10,10), for instance. Instead, we can create a function that generates a random number when called:

userfunction_random.png

This way is straightforward, creating a matrix with random coefficients. Another more elaborated example is creating a function that constructs a tri-diagonal matrix given three numbers. Therefore, every time we want to create a tri-diagonal matrix, we need to call this function with the terms of the upper-diagonal, diagonal and lower-diagonal.

userfunction.png

Programming

We can use some programming functions. You can see the basic ones here. For instance, by creating a list as before, we can efficiently compute the square of the first primes.

programming.png

Plotter

WIRIS graphics live within a plotter. When this plotter is interactive, you have a toolbar that lets you change some of its configuration; centre, zoom, show axes, etc...

plotter.png

You can also change all the settings using commands. The available options are listed in the Manual (plotter).

manual.png

You can first change options interactively, then get the equivalent commands using the button Save plotter movements.

save.png

One must distinguish between the general plotter options and each graphic object's particular options that live in it. The possibilities of objects are set using plot() and are also listed in the Manual (plot).

Here we'll discuss only the general plotter options, not the objects.

Create and use

You can create new plotters using the command plotter(). Each plotter has its individual configuration. The created plotters have sequential automatic names: plotter1, plotter2, plotter3 ... but can be assigned to a variable to use another name. When a plotter is completed, the command returns its name.

names.png

You can set the plot to use in the command plot(). If not specified, then it will use the last created plotter. If there is no plotter yet, a new one will be made with default options. The command returns the name of the used plotter.

news.png

The command represents () behaves like plot(), but when you create a new plotter, then it automatically changes some options. If you don't want this behaviour, then modify the options of plotter1 after.

represent.png

Plotter options can be set at the time of plotter creation by using the command plotter()or later by using the command attributes(). These options can be written as a vertical list using the key combination Shift + Enter.

vertical.png

Plotter options are of Table data type so that they can be manipulated as usual. You can get the possibilities of an already created plotter by using the command attributes() and assigning them to a variable. For example, one can access a value using parentheses.

table.png

Another example: you can combine multiple lists of options using the &.

combine.png

Size

The dimensions of the displayed area can be set in two ways:

  • Giving both width and height

  • Or giving only one, and aspect_ratio.

The dimensions of the window can also be set in the same way.

aspect_ratio.png

Grid

The grid density is automatic and depends on the dimensions of the window and the displayed area. For example, to get a grid of 1 unit, the window_width must be between 12 and 24 times the width.

In recent versions of WIRIS, there are commands for controlling the density of the grid. And in addition to the primary grid, you can use a sub-grid.

subgrid.png

See this complete example:

complete.png
result.png