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

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

by ali rosta -
Number of replies: 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.

Average of ratings: -
In reply to ali rosta

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

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of 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.
Average of ratings: Useful (1)
In reply to Dominique Bauer

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

by 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:

Average of ratings: Useful (1)
In reply to ali rosta

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

by 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


Average of ratings: Useful (2)
In reply to Bernat Martinez

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

by ali rosta -

Thanks, I am learning from these great examples!

In reply to ali rosta

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

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of 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.

Average of ratings: Useful (1)
In reply to Dominique Bauer

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

by 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?

In reply to ali rosta

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

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of 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.