How can I assess Symbolic Units and use assessVariableEqual to admit tolerances in MATLAB Grader simultaneously ?
4 次查看(过去 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.
0 个评论
回答(1 个)
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 个评论
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))
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!