MATLAB Grader. How to check vectroization in students solution?

조회 수: 2 (최근 30일)
BLP
BLP 2020년 3월 26일
편집: Cris LaPierre 2023년 10월 10일
Hi,
I would like to chck in MATLAB Grader if the students have used vectorization, eg. they write in their solution
x = (1:5).^(5:-1:1)
instead of
x = [1^5 2^4 3^3 4^2 5^1]
Is it possible?
  댓글 수: 1
Martin Rudolph
Martin Rudolph 2020년 6월 2일
편집: Martin Rudolph 2020년 6월 2일
Hello,
Referring to:
you could try something like that (with sprintf values from the reference solution could also be used):
SolutionFile = fileread('solution.m');
if ~contains(SolutionFile,'(1:5).^(5:-1:1)')
error('You did not vectorized the code as intended, please refer to the following example...')
end
or something less specific to allow alternative solutions:
if ~contains(regexprep(SolutionFile,'\s',''),'.^')
error('You did not used the elementwise power operator')
end
or
MaxNumber = 4;
NumberOfPowerOperators = numel(strfind(SolutionFile,'^'));
if NumberOfPowerOperators>MaxNumber
error('You used the power operator to often, it seems you did not vectorized your code properly')
end
Using splitlines and a loop you could also check each line for the amount of used operators. However, even if you write a complex test you cannot consider all possible solutions by the students. But a few lines of code may help you to identify strange solutions for a manual review.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 3월 27일
편집: Cris LaPierre 2023년 10월 10일
There is no built-in way to check that they used element-wise operators (.^).
You can prohibit the use of the keyword for, to avoid their solving it with a for loop.
My suggestion would be to assign the number to use randomly. That way, they can't hardcode their solution.
% provide the following as locked line in the student template
n = randi([4,10]);
% Student provides their solution underneath
x=(1:n).^(n:-1:1);
Because the reference and learner solutions share the same random number seed, the reference solution would just be
n = randi([4,10]);
x=(1:n).^(n:-1:1);
  댓글 수: 6
Cris LaPierre
Cris LaPierre 2020년 3월 27일
편집: Cris LaPierre 2020년 3월 27일
Let me recommend our Teaching with MATLAB self-paced course. I'd suggest quickly browsing all the chapters, as they all focus on our resources for teaching online. Chapter 6 in particular covers MATLAB Grader.
Also, Grader comes with some pre-built problems. The Getting Started with MATLAB Grader collection was specifically designed to help you get started. The last page of the Teaching with MATLAB course contains a table that helps identify problems to use as a template for common requests (working with files, random numbers, etc). For example, look at the Coordinate transformations Navigating a robot problem to see how you can use random numbers to create variables for your students to use.
Cris LaPierre
Cris LaPierre 2020년 3월 27일
Grader is essentially a variable checker. It is not a good solution for interactive/gui exercises. It should work well for your laboratories provided the code does not cause grader to time out (<1 minute to run and assess code).

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  원격 교육 커뮤니티

카테고리

Help CenterFile Exchange에서 Use Content in an LMS Course에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by