How can I assess Symbolic Units and use assessVariableEqual to admit tolerances in MATLAB Grader simultaneously ?

13 次查看(过去 30 天)
I created a MATLAB Grader problem where the students are supposed to check some literature tables to get some information about the material properties in order to answer it. The answer might vary a little depending of the source of their tables so I used coded tests to modify the tolerance.
assessVariableEqual('myVariable', referenceVariables.myVariable,'RelativeTolerance',0.03);
It worked fine. But now I am intending for the students to do the same problem including physical units. I am trying to assess that as part of the tests and I'm having dificulties with the assessVariableEqual. Whenever I include the sym units as part of the problem, the test tolerances seem to dissapear; it will grade correct only if the value is exaclty the one on the reference solution.
I tried separateUnits and then assess for the value and for the units separately, but now it shows that the variable I compare should be a type char and not sym.It is mentioned in the documentation that the learner variable is type char, but the correct (reference variable) is any data type. So I try to convert the learner variable into char and then assess, but now it says the value is not correct.

回答(1 个)

Cris LaPierre
Cris LaPierre 2022-5-27
编辑:Cris LaPierre 2022-5-27
I believe this answer is related:
Your observation is correct - when your variable is symbolic, they must be exactly equal. It is not possible to set a symbolic tolerance.
As an aside, you will see similar behavior with numberic variables if your variable and tolerance value are not of the same data type (e.g. variable is uint8 and tolerance is double). When the variable and tolerance data types are different, the tolderance is ignored.
If you could share a specific example, we could see if a workaround is possible.
  5 个评论
Juan José Cano Solórzano
编辑:Juan José Cano Solórzano 2022-6-1
The value should be the temperature of a fluid after a thermal process, the Units are Celsius.
I was checking and it seems that if the learner uses Fahrenheit it does prompt the error; the test works fine. But if the learner uses Kelvin it goes through, as if it was on Celsius; the test "doesnt work".
So I believe the point is that a single unit of u.Kelvin and u.Celsius represent the same amount of temperature. And its right, if you add 2 °C to something its the same as if you add 2 K. The actual difference is the shift of the Celsius scale.
Therefore the main issue here is about how to handle this kind of problem, where you are asking the student for a temperature (e.g Triple point of water : 273.16 K) and the test wont differentiate that from 273.16 C
Cris LaPierre
Cris LaPierre 2022-6-1
Ok, I see now. The issue is that Units is still symbolic. I would suggest either using an assert statement with isequal to check the units, or to first convert the units to string using symunit2str.
Assuming the reference solution is defined as follows
u = symunit;
% Triple point of water
T = 273.16*u.Kelvin
and the learner solution is
u = symunit;
% Triple point of water
T = 273.16*u.Celsius
Option 1: assert. I've included a custom error message that tells the user if the solution fails due to incorrect units.
% separte units
[Data,Units] = separateUnits(T)
[refData,refUnits] = separateUnits(referenceVariables.T)
assert(isequal(Units,refUnits),'Your temperature units are incorrect')
Optino 2: assessVariableEqual. Note that, if incorrect, the error message will include the variable name 'Units'. This is not a variable the learner created, so may actually confuse the learner.
% separte units
[Data,Units] = separateUnits(T)
[refData,refUnits] = separateUnits(referenceVariables.T)
Units = symunit2str(Units)
% compare
assessVariableEqual('Units',symunit2str(refUnits))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Formula Manipulation and Simplification 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by