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

2 views (last 30 days)
adam soker on 1 Apr 2022
Edited: Cris LaPierre on 4 Apr 2022
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.

Cris LaPierre on 1 Apr 2022
Edited: Cris LaPierre on 4 Apr 2022
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.
Cris LaPierre on 1 Apr 2022
Here is a picture of how I set up the assessment test.