Skip to content

Commit

Permalink
Add example exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
magaupp committed Dec 30, 2024
1 parent 86c680c commit 41a9a27
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 27 deletions.
28 changes: 28 additions & 0 deletions src/main/resources/templates/matlab/exercise/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
* text=auto

*.fig binary
*.mat binary
*.mdl binary diff merge=mlAutoMerge
*.mdlp binary
*.mex* binary
*.mlapp binary
*.mldatx binary
*.mlproj binary
*.mlx binary
*.p binary
*.sfx binary
*.sldd binary
*.slreqx binary merge=mlAutoMerge
*.slmx binary merge=mlAutoMerge
*.sltx binary
*.slxc binary
*.slx binary merge=mlAutoMerge
*.slxp binary

## Other common binary file types
*.docx binary
*.exe binary
*.jpg binary
*.pdf binary
*.png binary
*.xlsx binary
36 changes: 36 additions & 0 deletions src/main/resources/templates/matlab/exercise/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Autosave files
*.asv
*.m~
*.autosave
*.slx.r*
*.mdl.r*

# Derived content-obscured files
*.p

# Compiled MEX files
*.mex*

# Packaged app and toolbox files
*.mlappinstall
*.mltbx

# Deployable archives
*.ctf

# Generated helpsearch folders
helpsearch*/

# Code generation folders
slprj/
sccprj/
codegen/

# Cache files
*.slxc

# Cloud based storage dotfile
.MATLABDriveTag

# buildtool cache folder
.buildtool/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function avg = averageGradeByStudent(grades)
% TODO: Task 2
end
3 changes: 3 additions & 0 deletions src/main/resources/templates/matlab/exercise/finalGrade.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function g = finalGrade(grades,weights)
% TODO: Task 3
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function avg = medianGradeByAssignment(grades)
% TODO: Task 1
end
3 changes: 0 additions & 3 deletions src/main/resources/templates/matlab/exercise/square.m

This file was deleted.

49 changes: 49 additions & 0 deletions src/main/resources/templates/matlab/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Grading Statistics

In this exercise, you will analyze student performance based on a matrix of
grades. Each row in the matrix represents a student, and each column represents
an assignment.

Your task is to implement three functions that compute statistical measures for
this data. Each function has a specific purpose, described below:

## Task 1: Median Grade by Assignment
Compute the median grade for each assignment across all students. The result
should be a row vector where each element corresponds to the median of a
specific assignment (column).

- **Function to Implement**: `medianGradeByAssignment()`
- **Input**: A matrix `grades` where rows are students and columns are assignments.
- **Output**: A row vector of medians, one for each assignment.

[task][Median Grade by Assignment](testMedianGradeByAssignment)

---

## Task 2: Average Grade by Student
Calculate the arithmetic mean grade for each student across all their assignments.
The result should be a row vector where each element corresponds to a student's
arithmetic mean grade.

- **Function to Implement**: `averageGradeByStudent()`
- **Input**: A matrix `grades` where rows are students and columns are assignments.
- **Output**: A row vector of averages, one for each student.

[task][Average Grade by Student](testAverageGradeByStudent)

---

## Task 3: Final Grade
Determine the weighted final grade for each student. In addition to the
`grades` matrix, you are provided with a row vector `weights` (summing to 1)
that represents the weight of each assignment. Compute the weighted average for
each student and round the result to 1 decimal place. The result should be a
row vector where each element corresponds to a student’s final grade.

- **Function to Implement**: `finalGrade()`
- **Input**:
1. A matrix `grades` where rows are students and columns are assignments.
2. A row vector `weights` with the same number of elements as columns in the `grades` matrix.
- **Output**: A row vector of weighted final grades, rounded to 1 decimal place.

[task][Final Grade](testFinalGrade)
28 changes: 28 additions & 0 deletions src/main/resources/templates/matlab/solution/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
* text=auto

*.fig binary
*.mat binary
*.mdl binary diff merge=mlAutoMerge
*.mdlp binary
*.mex* binary
*.mlapp binary
*.mldatx binary
*.mlproj binary
*.mlx binary
*.p binary
*.sfx binary
*.sldd binary
*.slreqx binary merge=mlAutoMerge
*.slmx binary merge=mlAutoMerge
*.sltx binary
*.slxc binary
*.slx binary merge=mlAutoMerge
*.slxp binary

## Other common binary file types
*.docx binary
*.exe binary
*.jpg binary
*.pdf binary
*.png binary
*.xlsx binary
36 changes: 36 additions & 0 deletions src/main/resources/templates/matlab/solution/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Autosave files
*.asv
*.m~
*.autosave
*.slx.r*
*.mdl.r*

# Derived content-obscured files
*.p

# Compiled MEX files
*.mex*

# Packaged app and toolbox files
*.mlappinstall
*.mltbx

# Deployable archives
*.ctf

# Generated helpsearch folders
helpsearch*/

# Code generation folders
slprj/
sccprj/
codegen/

# Cache files
*.slxc

# Cloud based storage dotfile
.MATLABDriveTag

# buildtool cache folder
.buildtool/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function avg = averageGradeByStudent(grades)
avg = mean(grades,2).';
end
3 changes: 3 additions & 0 deletions src/main/resources/templates/matlab/solution/finalGrade.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function g = finalGrade(grades,weights)
g = round((grades * weights.').',1);
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function avg = medianGradeByAssignment(grades)
avg = median(grades);
end
3 changes: 0 additions & 3 deletions src/main/resources/templates/matlab/solution/square.m

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/resources/templates/matlab/test/tests/GradeTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
classdef GradeTest < matlab.unittest.TestCase
properties
grades
end

methods (TestClassSetup)
% Shared setup for the entire test class
end

methods (TestMethodSetup)
% Setup for each test

function setupGrades(testCase)
testCase.grades = [1.3 3.3 4.0 4.7
2.7 1.7 4.0 1.7
1.7 3.7 3.0 4.3
4.3 2.3 1.7 3.3
2.3 3.7 2.0 5.0];
end
end

methods (Test)
% Test methods

function testMedianGradeByAssignment(testCase)
actual = medianGradeByAssignment(testCase.grades);
expected = [2.3 3.3 3.0 4.3];
testCase.assertEqual(actual,expected,"median is incorrect",AbsTol=0.0001);
end

function testAverageGradeByStudent(testCase)
actual = averageGradeByStudent(testCase.grades);
expected = [3.325 2.525 3.175 2.9 3.25];
testCase.assertEqual(actual,expected,"average is incorrect",AbsTol=0.0001);
end

function testFinalGrade(testCase)
weights = [0.1 0.1 0.5 0.3];
actual = finalGrade(testCase.grades,weights);
expected = [3.9 3.0 3.3 2.5 3.1];
testCase.assertEqual(actual,expected,"final grades are incorrect",AbsTol=0.0001);
end
end

end
21 changes: 0 additions & 21 deletions src/main/resources/templates/matlab/test/tests/MathTest.m

This file was deleted.

0 comments on commit 41a9a27

Please sign in to comment.