Basic Guide - Wiris CAS
Atención
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 here.
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](image/uuid-6d2efb87-d1f7-0bfa-9f40-5a939b0c8914.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](image/uuid-f9264bbf-c376-2303-c2ea-59e7ffbb4af9.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](image/uuid-09c1862a-3dae-f8e5-52d6-ad78c35e73ae.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](image/uuid-bbd7ef03-d15d-5f5f-9843-9fb42b10d6e5.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](image/uuid-8b2f562a-75b1-582a-1d4e-d8eba34a8ab0.png)
Polynomials and expressions
Polynomials are created with numbers times a power of a variable.
![polynomials_constructor.png](image/uuid-b74f2f37-5ac5-9001-6f7e-b874a41f4e58.png)
We can sum, multiply, divide and, for instance, find roots of polynomials.
![polynomials_operations.png](image/uuid-1b674b41-70ee-4ad5-f925-bb6c2e71cc7e.png)
We can create more complex expressions and operate with them.
![expressions.png](image/uuid-84eef7ba-01e6-8ce4-c969-d52455e6951c.png)
Vector and Matrix constructor
Vectors
Vectors are constructed with square brackets []
, and commas ,
separate the elements.
![vector_constructor.png](image/uuid-ccc71c48-f2df-4e95-0baa-77b0e5ec3eef.png)
We can sum vectors or compute the scalar product between them.
![vector_operations.png](image/uuid-34713ee1-1f9d-4e5b-c804-ff43831bbbd5.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](image/uuid-b930ecec-452a-75f1-c6a4-e2d0522a6bc1.png)
As vectors, we can sum and multiply matrices (as long as dimensions match).
![matrix_operations.png](image/uuid-d27fbacc-a041-c011-5fd0-5b9532a7a039.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](image/uuid-c6e7de58-1501-fd01-54a2-3f355c97b01c.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:
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](image/uuid-a87f6cfd-9347-e008-6c51-b6c03450e962.png)
or we could greatly simplify it to the following:
![lc_ex1.2.png](image/uuid-e9d1d110-29d4-5eef-e538-680153bf9634.png)
The command where
comes in when we want additional restrictions. To get only the even numbers, for example:
![lc_ex1.3.png](image/uuid-c3059853-1ff0-bf14-05be-33831877b6a6.png)
Alternatively, we could, of course, have gone with:
![lc_ex1.4.png](image/uuid-252e9744-19b5-0771-c9cf-67222b7967e9.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](image/uuid-98a65f49-bdd7-42bf-dd27-cbb0d3badea1.png)
As you may notice, the first expression need not explicitly depend on . We can think of 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](image/uuid-574b71c5-0b26-2aed-7c9e-dba80fd6141a.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](image/uuid-ca0b9877-b896-db2e-b146-ac4a6b9b35a5.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](image/uuid-ed407d5e-e892-3f84-6c89-5224d2e07bae.png)
Example 5
It is also possible to create matrices using this notation. For instance, creating a matrix with random coefficients is as simple as this:
![lc_ex5.1.png](image/uuid-bd9c4264-26bd-aabf-6039-9cca5ae904b1.png)
Geometry
Wiris CAS allows us to deal with geometrical figures such as points, lines, planes and conic sections.
![geometry_statement1.png](image/uuid-896f387b-1265-bb1d-86db-b38ea13af97d.png)
![geometry_plotter1.png](image/uuid-b10720be-b24d-7e50-20c8-2195e2dd1e13.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](image/uuid-d0b543a8-e39e-c60c-1be7-3ad923193b84.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](image/uuid-ceec5869-e153-5089-7782-eb603ad65c29.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](image/uuid-8447e4af-d74b-6ede-63ab-b02e55aa6092.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](image/uuid-e2e83fd3-4868-ba06-4eaa-642a47ce91ad.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](image/uuid-507aca9e-9af3-118a-7456-74aa0e1c9191.png)
You can also change all the settings using commands. The available options are listed in the Manual (plotter).
![manual.png](image/uuid-bb8c37d3-49da-4a9e-578b-1d75927515a2.png)
You can first change options interactively, then get the equivalent commands using the button Save plotter movements.
![save.png](image/uuid-01c79853-412c-6d62-1d21-929c31452c75.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](image/uuid-7b6ad9e2-3590-b1f2-a08d-bc0a5f59deaf.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](image/uuid-3eca5b56-2e04-db26-1c02-d9dc543a6882.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](image/uuid-8b788b2b-018b-4ff9-f7b1-9f30a2da5c3c.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](image/uuid-45da53ab-a21a-a98b-da96-fcdc0c738bb1.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](image/uuid-358eb4fe-a162-bde9-e9ee-5df4d642daa3.png)
Another example: you can combine multiple lists of options using the &
.
![combine.png](image/uuid-3d70b76e-dacf-aba3-1d45-8f863a211bb3.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](image/uuid-ea19aec5-6f35-6500-6023-06ec1edb012c.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](image/uuid-0b2c5fe1-e6cc-6fd0-f17d-3dd68d00c68f.png)
See this complete example:
![complete.png](image/uuid-3d3bb375-7db5-8381-291c-5d9857bafb2e.png)
![result.png](image/uuid-e69aafae-3d59-a01d-ec09-4d1918577c05.png)