Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
378 views
Kernel: Octave

Using Cocalc and Cody Coursework To Teach MATLAB

Cocalc can be used to create notes containing runnable code and Cody Coursework allows you to automate the marking process of MATLAB problems and provide instant feedback to students. Together they are a useful toolset for teaching MATLAB. In this document I have outlined how to use both systems.

Using Cocalc To Create Jupyter Notebooks


Cocalc is a free to use website that allows one to create Sagemath worksheets, Jupyter Notebooks and Latex documents for free. Using Jupyter Notebooks you can combine text with executable code cells, which is what makes Cocalc potentially valuable for teaching MATLAB.

In order to create a Jupyter Notebook you must first create a free account with Cocalc. Then follow these steps:

  • Create a new "project".

  • Click "create" to create a new notebook.

  • Change the name of the file or leave it as the default which is the date/time of creation.

  • Select the type of file. In this case we want "Jupyter Notebook".

  • Click on "Kernel" towards the top of the page and choose "Octave" (a free language almost the same as MATLAB)

You now have a new notebook in which you can execute code almost exactly the same as you can with MATLAB.

Using cells

You will see a box in which you can type at the top of the document. This is called a cell. The default cell type is "Code" which you should see in a drop down menu to left of the green "Save" button. This can be changed to "Markdown" or "raw" which allows one to have executable code and formatted text/links/images/videos etc all in the same document.

To execute the code in a code cell hit Shift+Enter.

Markdown cells, such as this one, require you to write and format text while in a code cell type, and then change the cell type to markdown to apply the formatting. The syntax for markdown can be found here.

To create a new cell, hover your mouse below or above an existing cell and click on the blue line that appears. To delete a cell, click in the space to the left of the cell text box but inside the green or blue border that appears when a cell is selected and press the "D" key twice in a row.

Below is an example of a code cell:

x=4; y=x^2
y = 16

Making your notebook public

It is possible to share a Jupyter Notebook you have made with Cocalc publicly. To do this, go to "Files", click the checkbox next to the item you wish to make public and the option to "share" should appear. Click this and then click "Make item public". Copy the link provided to share.

Copying someone else's notebook into your own project

If someone else has shared a public notebook with you, then it is possible to copy it into your own project so that you have your own version to use and edit. For example, if you wanted to copy this notebook then you can:

  • Click "Files" in the top left hand corner. You will see this file listed as public.

  • Click the check box to the left of the word "Public". You will see the options to copy or download the file appear above.

  • Click "Copy", select the project you wish to copy it to and then confirm by clicking "Copy 1 item".

Now if you go back to your projects and open the one you copied the notebook to, you will be able to open it and edit as you wish.

In this way students will be able to play with the code in the notes without changing the original document.

Cody Coursework


Cody Coursework is an online assessment system for MATLAB and other Mathworks products such as Simulink. You can create problems for students to complete and use the test suite to automate the marking process.

In order to get started with Cody Coursework you must first log in with the Mathworks account you should have if you have downloaded MATLAB. Then you can:

  • Create a "course" and choose the start and end dates.

  • Create an "assignment" and choose the due date.

  • Click "people" to invite students to the course via email. They don't need a license or to have installed MATLAB on their computer to use Cody.

  • You can also invite other instructors to be able to view and edit the problems.

  • Create a "problem".

  • Use this markup to format questions.

  • Write a solution template - the solution can either be a function or a script.

  • Write tests.

  • Write a reference solution to check whether the test suite is working correctly.

  • View student solutions on a graph that shows correct student solutions as green circles and incorrect solutions as crosses, with the size of the solution on the y axis and time of submission on the x axis. This makes it easy to see which problems students are struggling with.

The test suite

Cody Coursework allows you to create visible and hidden tests. Students can test their code with the visible tests before submitting, after which the hidden tests will run. Using hidden tests means that students can't just write code that passes the visible tests.

Individual tests are separated by two percentage signs: %%

You can call the student's solution in your test and use assert() to assess whether something is true, for example:

assert(isequal(a, b))

To assess whether a certain keyword or function is present in the student's code you can use:

assessFunctionPresence('a_keyword','FileName','your_fcn.m')

You can provide feedback if a specific error has been made using the "assessVariableEqual" function:

assessVariableEqual('variable1',0.5,'AbsoluteTolerance',0,'Feedback',msg);

As you can see, you can also choose the tolerance of the values that will be accepted.

More information on tests can be found here.

An example test would would be:

%% y=students_function(10); y_correct=2; assert(isequal(y,y_correct))

To test plot outputs you can test whether correct x and y data are present as well as assessing the presence of the plot function:

%% x=0:0.1:10; y=x.^2+1; h=plotgraph(0,10,0.1); %run student solution X=get(h,'XData'); %use the "get" function to extract the X and Y data Y=get(h,'YData'); assert(isequal(X,x)) assert(isequal(Y,y)) assessFunctionPresence('plot','FileName','plotgraph.m')

You can find many problems other people have made with Cody here.

When it comes to scripts and functions that animate a graph or have other such complex outputs, Cody is likely not the best way to assess. Additionally, if you require marking of the structure and readability of the code then that will have to be done manually. For the early stages of learning MATLAB, however, Cody provides an excellent way to test fundamental knowledge.