# Randomization in Matlab Grader

37 views (last 30 days)

Show older comments

If I'm teaching a class with hundreds of students and I don't want them to each have the same problem, is it possible to have each problem be different on a per-student basis? For example if Matlab grader has access to an ID number which is unique to that student then when programming the question I could use that number when generating the student's question, and reference solution. Something like the following, where the guts of ##xxx## gets evaluated to produce numbers which are unique to the student, and shown to the student:

Problem Description and Instructions:

Assign x=##ID%8## and y=##ID%10##

Calculate x/y and assign the result to z.

Reference Solution:

x = ##ID%8##

y = ##ID%10##

z = x/y

##### 0 Comments

### Answers (2)

Alex Pedcenko
on 17 Jun 2020

Edited: Alex Pedcenko
on 17 Jun 2020

There is a way to achieve some level of individualisation in Grader. Unfortunately it is not possible to generate problem description, which is individual for each student. The workaround is that you can make a list (printed or electronic sheet of sorts), which states parameters of each question for each student.

_________________________

Example:

Question in Grader: Plot a graph of a function y(x) from in your Question 1 (refers to the sheet with values) for N values of x in the the domain of . Values of N, x_min and x_max are individual for each student.

Assign your Student ID number to the variable id.

__________________________

Comment: function y(x), values of N, x_min and x_max are provided to each student individually (e.g. you can make a sheet with their id numbers and list y(x), N, etc for each student id and give the sheet during a test or on Moodle etc. if Grader could generate (or alter) question text based on externally attached script, life could be much easier, but I guess security concerns...

To provide Grader with individual values of y,N.x_min,x_max we can use "Files referenced" section in question specs. We can upload additional m-file or p-file which contains all student id's in an array and other arrays with all other parameters. E.g. I call this file "testit.m" (same as the name of the function inside). The file testit.m is below (not visible to students):

function [ y,n,x_min,x_max ] = testit(student_id)

% functions and id's are stored in cell arrays

% can also load all that from some data file

IDs={'111111','222222','333333'}; % sample student id numbers,

% one of id's (e.g. 1st) can be fake for testing purposes

functions_to_plot={@sin,@cos,@exp_cos}; % functions corresponding to student id numbers

% for the "assessment stage", can be built-in or custom made (see example of custom function below)

% other numerical parameters made individual for each student:

N=[100,200,300];

x_1=[0,-pi,0]; % x_min for plotting

x_2=[2*pi,pi,3*pi]; % x_max for plotting

% finding which id to use

id=num2str(student_id);

index=find(contains(IDs,id)); %searching for id in cell array

if strcmp(cell2mat(IDs(index)),id) % in case only part of ID was used

disp(['ID found: ', id]);

else

index='';

disp('ID not found!');

end

y=functions_to_plot(index); % function for student with given student_id

n=N(index); %

x_min=x_1(index);

x_max=x_2(index);

end

% example of custom function for a student

function y = exp_cos(x)

y = exp(x).*cos(x)

end

Then Referense solution function looks like this:

function [y, x, id, h] = myFunction(id)

if ~exist('id','var') % just to pass "ref. solution validation" stage

id=111111; % should be one of id's in testit.m

end

[func,n,x_min,x_max] = testit(id);

x=linspace(x_min,x_max,n);

% take vector x and evaluate y

y=func{1}(x); % this is the only way I found as "eval" and alike won't work

h=plot(x,y);

end

The learner template:

function [y,x,id,h] = myFunction(id) % lock this line

id='222222'; % Note to student: make sure you define your Student ID here (teacher: leave value of id empty)

%% following lines are as an example solution for this forum: they are not shown to student in actual question

x=linspace(-pi,pi,200); % values for id 222222

y=cos(x); % can also try sin(x) [id=111111] or exp(x).*cos(x) [id=333333]

%%

% assign plot to handle h (optional in case you want to check plot properties, like line style, color etc)

h=plot(x,y); %

"How to call this function" box

% do not change anything in this box

id=0;

myFunction(id);

Finally the Assessment function

% Run learner solution:

[y,x,id,h] = myFunction();

% Run reference solution and get ref. variables:

[yRef, xRef, idRef, hRef] = reference.myFunction(id); % is is the only place where "id",

% provided by the student is actually passed to the ref. function to get the correct solution

% can also extract values from "h" and "hRef", e.g. to check if plot parameters are right

% Compare student result with reference solution:

assessVariableEqual('x', xRef,'Feedback','vector x appear to be wrong');

assessVariableEqual('y', yRef,'Feedback','vector y appear to be wrong');

Now, If one is concerned that student will not use their ID and pass solution validation with ID of their mate. ID should not necessarily be real student ID, they may be some unique strings of random characters pre-generated before the test. In this case all you need to change is just one line in textit.m with cell arrays of used id's.

Also after the test you can obviously check if ID they used is ID they should have used, but the main purpose I guess is to avoid extra work :)

Also testit.m can contain all info for all the questions in the assignment, not just one (may need to use unique variables for parameters of each question though)

Cris LaPierre
on 15 May 2020

Edited: Cris LaPierre
on 21 May 2020

MATLAB Grader allows you to use random numbers to accomplish what you want. Both the reference and learner solutions share the same seed, so generate the same random numbers.

There are two example problems that do this in the Getting Started with MATLAB Grader problem collection.

- Coordinate transformations Navigating a robot
- Finding a signal through the noise

Typically you would create the variable for the students in the Learner Template and lock that line of code to ensure they do not accidentally change it. You can use this approach to create a scalar, vector or matrix of values for them. Every time they run the problem, the variable will generate new values.

To answer your other questions, MATLAB Grader does not have access to the student id, and does not have the capability to display a variable value in the problem description.

##### 7 Comments

Jeff Alderson
on 8 Mar 2021

### Communities

More Answers in the Distance Learning Community

### See Also

### Community Treasure Hunt

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

Start Hunting!