Evaluating expressions

Evaluating expressions

by Vincent Guirardel -
Number of replies: 1

Hello,

This is another feature request for the Formulas question type.

We have the function diff that allows to tell whether 2 expressions agree. But this is not sufficient in some contexts.

The php code is able to evaluate an expression after giving values to the variables. So it would be helpful to have access to this method.

Here is what I have in mind:

Input: expression, name of variable, list of values for variable [,name of other variable, other list of values of same size]

Output: list of values obtained after evaluation of the expression after substituting the variable by their values.

Example:

evaluate("2x+1","x",[0,1,2])  would return [ 1, 3, 5]

evaluate("2x+y","x",[0,1,2],"y", [-1,-1,1]) would return [ -1, 1, 5]

I may try to propose some code if I find time... and if you think this is appropriate (in particular, does the syntax look ok?)

_____

Applications I have in mind:

Question: Give a cartesion equation of the plane generated by the vectors [1,2,-3],[1,0,-1].

Possible answers: x+y+z  , or more generally ax+ay+az (so there is no uniqueness of the answer).

I can ask for the coefficients in front of x,y,z, but if I want the student to gives the answer in the form of an expression, I need to evaluate this expression...


Average of ratings: -
In reply to Vincent Guirardel

Re: Evaluating expressions

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Vincent,

You could see if this can be done using the Grading variables and Grading criterion.

I'm going to try it on my side later this week.