formulas qtype: define algebraic variable using expressions of another algebraic var

formulas qtype: define algebraic variable using expressions of another algebraic var

por ali rosta -
Número de respuestas: 7

Is it possible to define nf var (below) based on a previously defined algebraic var? like:


Global Variables

      n = {1:20};

      nf = 2*n-sin(3*n);


It is very useful as the answer for several parts of my question depend on "nf" and repeatedly typing the expression for it is awkward/error prone.

Promedio de valuaciones (ratings): -
En respuesta a ali rosta

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por Dominique Bauer -
Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Plugin developers

n = {1:20}; has the syntax of a Random variable, not of a Global variable. If I understand what you are trying to do, use a 'for' loop in the Global variables:

nf = fill(21,0);
for (n:[1:21]) {
  nf[n] = 2*n-sin(3*n);
}

Note:

  • Arrays always start at 0.
  • The last index is not included in the loop.
Promedio de valuaciones (ratings):Useful (1)
En respuesta a Dominique Bauer

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por ali rosta -
Thanks you understood and showed the solution, however made some other confusions!
Why n={1:21}; is only a Random var? In the doc it uses the same syntax for algebraic vars:

Promedio de valuaciones (ratings):Useful (1)
En respuesta a ali rosta

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por Bernat Martinez -

Hi Ali, 

At this stage may be it would be helpful to see some FORMULAS working examples at

https://moodle.scorepro.eu/course/view.php?id=52

Hope it helps


Promedio de valuaciones (ratings):Useful (2)
En respuesta a ali rosta

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por Dominique Bauer -
Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Plugin developers

Ali,

The use of random variables defined as a set of numbers, denoted with { }, is common, simple and well explained in the documentation.

But you're right, algebraic variables can also be defined as sets of numbers, also denoted with { }. They can be defined in the global variables field or the local variables field and used for evaluation points in the algebraic formula answer type or with the diff() function also used to set the _d grading variable.

Promedio de valuaciones (ratings):Useful (1)
En respuesta a Dominique Bauer

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por ali rosta -

"algebraic variables can also be defined as sets of numbers"


Dear Dominique, Can it be other than a set of numbers or a single number? I'm under the impression that this is the only possible (meaningful?) choice for algebraic variable.  Can you show an example of other types of algebraic vars?

En respuesta a ali rosta

Re: formulas qtype: define algebraic variable using expressions of another algebraic var

por Dominique Bauer -
Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Plugin developers

The point was that { } are mainly used for random variables, but also for algebraic variables. Sets usually consist of several numbers.

Note that while 'sets' are designated with { } and are associated with random values, 'lists' are designated with [ ] and their values are not random. You can have lists of numbers and lists of strings. Lists are like arrays, that is, you can address specific elements of a list, for example if A = [4,5,6], then A[0] gives 4.