Same values's aswer in MATLAB Grader but identified as a mistake.

3 次查看(过去 30 天)
The references solution for 'f' is:
a = 4
m = 3
b = -3
l = 6
C1 = -0.42
C2 = -4.00
C3 = -2.07
C4 = 0.30
t = -10:0.1:10;
s = t.*(t>=0 & t<=1);
sa = (t-a).*((t-a)>=0 & (t-a)<=1);
sm = m.*s;
sb = (t/b).*((t/b)>=0 & (t/b)<=1);
sdr = (l-t).*((l-t)>=0 & (l-t)<=1);
f = C1*sa + C2*sm + C3*sb + C4*sdr;
The student's solution is:
f = ((-0.42)*t+1.68).*(t>=4 & t<=5)-12*t.*(t>=0 & t<=1) + (0.69)*t.*(t<=0 & t>=(-3))+(1.8-0.3*t).*(t<=6 & t>=5);
The solutions should be the same. But when them there is a size 1.6653e-16 error, so the student's answer is not accepted.

回答(1 个)

Cris LaPierre
Cris LaPierre 2022-4-1
编辑:Cris LaPierre 2022-4-4
How have you set up your assessment test? Are you using the Variable Equals Reference Solution test or a MATLAB Code test type? If MATLAB Code, have you incorporated tolerances into your equality check?
When I test the code you have shared in Grader, the learner solution's value of f is marked correct.
I used the drop down test "Variable equals reference solution" and entered f as the "variable name you want to compare". This automatically applies a +/- 0.1% relative or +/- 0.0001 absolute tolerance to the solution. This means a difference of 1.6653e-16 is considered equal.

类别

Help CenterFile Exchange 中查找有关 Test Execution 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by