During the preparation of my courses I came along the following problems:
- Allow alternative solutions
- Specific check of reoccurring student errors, with precise hints
- Check plots
which seem to be undiscussed until know. So here are some more specific examples including the solution (hope it may help you):
1)
These is locked code in the Learner Template, defining some important physical values:
% Definition of physical constants
c = 299792458; % speed of light [m/s]
h = 6.626070040e-34; % Planck's constant [Js]
e = 1.6021766208e-19; % elementary charge [C]
% Definition of units
eV = 1.6021766208e-19; % unit conversion: eV to J
The student is first requested to provide the following lines, which he has to be extract from a formulary:
% Define the photon energy E
E = [8047.8227, 8027.8416] % transition energies [eV]
Afterwards he has to calculate the wavelength in angstrom, the Reference Solution to this problem would be:
% Calculate the wavelength Lambda
Lambda = h*c./(E*eV); % wavelength [m]
Lambda = Lambda*1e10 % wavelength [A]
The two standard tests would be:
assessVariableEqual('E',referenceVariables.E)assessVariableEqual('Lambda',referenceVariables.Lambda)
However, a lot of students provided the following solution:
% Calculate the wavelength LambdaE = E*eV;Lambda = h*c./E; % wavelength [m]Lambda = Lambda*1e10 % wavelength [A]
The solution is completely correct, but the error which the first test returns since the E is redefined made the students insecure and animated them to provide further solutions which were incorrect. Thus, I replaced the first test by:
% Get reference variable
E_ref = referenceVariables.E;eV_ref = referenceVariables.eV;% Submitted variables can be addressed normally as long as the student defined it otherwise an error will be displayed similar to variable not declared.
% Conditioned comparison between the reference solution and the submitted solution
if ~exist('E','var') error('The submission must contain a variable named E.')elseif E==E_ref*eV_ref % allow for the alternative definition in Joule
assessVariableEqual('E', E); % this is a dummy test it is always true because the studends variable is compared to itself
else % check if the variable is defined in the actual requested unit electron volt
assessVariableEqual('E', E_ref,'Feedback','If the value is incorrect check if you have selected the experimental transition energy, if you have four decimal places and if it is specified in electron volt (avoid to redefine it, exception is the unit conversion to Joule).');end
2)
Check the example above also a lot of students calculated the wavelength as follows and did not recognized were the fault was:
% Calculate the wavelength LambdaE = E*eV;Lambda = h*c./E; % wavelength [m]
Thus, I replaced the second test by test which tells them if the result is completely incorrect or if they just forgot the conversion to angstrom:
% Get reference solution for x.
Lambda_ref = referenceVariables.Lambda;% Conditioned comparison between the reference solution and the submitted solutionif ~exist('Lambda','var') error('The submission must contain a variable named Lambda.')elseif Lambda==Lambda_ref*1e-10; error('You have calculated Lambda in meter, now convert it to angstrom to get the correct solution!')else % check if the variable is defined in the actual requested unit electron volt assessVariableEqual('Lambda', Lambda_ref,'Feedback','If you passed the first test, than you entered the equation wrong or your resulting unit is something like "rainbows per unicorn" ;) Check for correct unit conversion. The wavelength is requested in angstrom.');end
3)
The students have to load some data into the variable Voltage and plot it subsequently. The Reference Solution is (note: the line containing Fig_Voltage is locked in the Learner Template):
% Import the measured data from the file "tube_voltage.txt" to the variable Voltage
Voltage = importdata('tube_voltage.txt') % no semicolon to print structure elements
% Open figure (the assignment of the new figure to the variable Fig_Voltage is only necessary for the automated tests)
Fig_Voltage = figure(1);% Plotting
hold on % Plot the data using connected markers
plot(Voltage.data(:,1),Voltage.data(:,2),'-s') % Plot the axes labels
xlabel('Voltage [kV]') ylabel('Intensity [cps]') % Plot the title
title('Current: 20 mA')hold off
If we apply the standard tests we can check if Voltage is correct and if the functions like plot, xlabel, etc. were used. But some students provided a solution which was wrongly identified as correct using this basic assessment:
Voltage = importdata('tube_voltage.txt') % no semicolon to print structure elements% Open figure (the assignment of the new figure to the variable Fig_Voltage is only necessary for the automated tests)Fig_Voltage = figure(1);% Plottinghold on % Plot the data using connected markers plot(Voltage.data(1,:),Voltage.data(2,:)) % Plot the axes labels xlabel('Voltage [kV]') ylabel('Intensity [cps]') % Plot the title title('Current: 20 mA')hold off
Thus, I used the following complex tests for checking the plotted data and the usage of connected plot markers:
Test 1: Data check
% Do not extract the values from the reference plot, as it returns a handle to a deleted figure
% Define the data which should be plotted, as the data is checked in the first test we just check if the students data is plotted correctly
% Nice side effect even if the data is compromised the student is not punished for a cascading failure
PlotData_ref = Voltage.data'; % Check if the correct data is plotted
Axes = findall(Fig_Voltage,'type','axes');if size(Axes)~=[1 1] error('You assigned none or more than one axis to the figure Fig_Voltage!');else Plots = Axes.Children if size(Plots)~=[1 1]; error('You assigned none or more than one plot to the figure Fig_Voltage!'); else PlotData = [Plots.XData; Plots.YData]; assessVariableEqual('PlotData',PlotData_ref,'Feedback','If the value is incorrect, you may have switched the x and y axis or you are using the current instead of the voltage.') endend
Test 2: Plot markers
Axes = findall(Fig_Voltage,'type','axes');if size(Axes)~=[1 1] error('You assigned none or more than one axis to the figure Fig_Voltage!');else Plots = Axes.Children; if size(Plots)~=[1 1] error('You assigned none or more than one plot to the figure Fig_Voltage!'); else if ~strcmp(Plots.Marker,'none') && contains(Plots.LineStyle,'-') assessVariableEqual('Fig_Voltage', Fig_Voltage); % this is a dummy test it is always true because the studends variable is compared to itself else error('Either you did not connected your markers or used none.'); end endend
Tags: matlab, grader, code, test, assessment, complex, conditioned, alternative solutions, differentiable errors, figure, plot, submission, reference solution, assessVariableEqual, learner template, feedback, if, referenceVariable
Best Answer