## Create Script-Type Problems

To help your learners master MATLAB® coding skills, you can write a problem that you want learners to solve using a script.

To write a script-type problem:

• To add a problem to a collection: On the Content tab, click Add Problem in the desired collection.

• To add a problem to a Course: On the Courses tab, click the course you want to add a problem to. On the assignment where you want the new problem, click Add Problem.

3. Select an existing problem from your own collection or from MathWorks® Collections or create your own problem starting with a blank template.

If you need additional help while creating a function-type problem, click the question mark icon next to the item for instructions.

Tip

At any time, you can click Choose Different Problem to abandon the draft, return to Add Problem, and make a new selection.

While drafting the coding problem, remember to save your work in progress. You have two options:

• — You can continue developing this problem while it is in draft mode.

• — The problem is complete. If this problem is part of a course you are developing, the problem is viewable to learners when the course is published. Learners can view only those problems that are in the Final state. If you want to remove a problem from learner view after publishing it, open the problem and then click .

### Step 1. Describe Problem to Solve

1. Create a title and detailed problem description for the learner.

Using the rich text editor, you can include formatted text, equations, links, and images.

Note

When you write the problem description, clearly define the number and type of input variables and the number and type of expected outputs. Be specific about the types of values or units of measurement.

2. Optionally, provide data and code files that the reference solution, learner solution, and assessments can use. Add these items in Files Referenced.

3. Set Problem Type to Script. This setting tells MATLAB Grader that the learner solution must be formatted as a MATLAB script.

### Step 2. Write Problem Solution

Write a reference solution that you can then use to assess the learner solution.

• The Reference Solution is your solution. The learner cannot see this solution.

• By writing a reference solution, you can refer to the variables in this solution in your assessments and compare them to the variables in the learner solution.

### Step 3. Write Code and Comments to Assist Learners

Provide a solution template for the learner.

• The Learner Template provides code that the learner starts with to write their solution. You decide how much code to provide to the learner.

• Click the lock icon to keep learners from changing code you provide.

• Use comments to provide coding instructions and prompts to learners.

Provide the variable name you expect learners to use so that you can use the same variable in your assessments.

#### Preview Problem Display

To see how your content is formatted, click . The preview area displays the view that your learners see when solving the problem in MATLAB Grader.

You can interact with the to see assessment results, feedback, and error messages.

Learners also have the option of working on and submitting their solution using MATLAB Online™. They can code their solutions to MATLAB Grader problems using the workspace, Live Editor, and debugging features of MATLAB without having to download, install, or set up MATLAB.

To preview the problem as it will appear to learners in MATLAB Online:

1. Save the problem as final.

2. Click .

3. Click .

MATLAB Online displays the problem description, assessment and output tabs, and and buttons in a MATLAB Grader panel on the left side of your browser. As with other panels in MATLAB Online, learners can move the MATLAB Grader panel to the left or right side of the window.

### Step 4. Create Assessments to Test Learner Solutions

Assessments for script-type problems can be simple or complex; it all depends on the conditions you want to test for. This section provides a brief description of the UI elements. For more information about and examples for writing assessments for this type of problem, see Write Assessments for Script-Type Learner Solutions.

When a learner submits a solution, your assessments evaluate the learner solution. You can write as many tests as you think are necessary.

1. Specify the assessment method you want to use.

1. Under Assessment, select one of the assessment methods: Correct/Incorrect or Weighted.

• Correct/IncorrectMATLAB Grader treats the problem as pass/fail.

• Weighted — When creating multiple assessments for a single problem, you can choose to award partial credit for each test.

2. Decide if you want to show feedback for only the initial error.

MATLAB Grader assumes that the assessments are in an order where later tests depend on earlier tests being correct. When you select Only Show Feedback for Initial Error, MATLAB Grader shows detailed feedback for the first assessment that is marked incorrect but hides the feedback for subsequent incorrect assessments.

Hiding subsequent error feedback can help learners focus on what caused the first error. Fixing that error can fix all the subsequent issues. At any time, the learner can display this hidden feedback by clicking Show Feedback in their MATLAB Grader view.

2. Code the assessment.

2. Provide a brief description of the test.

3. Select a test type.

• ```Variable Equals Reference Solution``` — Check whether a variable in the learner solution equals the same variable in the reference solution within tolerance. Provide the variable name you want to compare.

• `Function or Keyword Is Present` — Provide the functions and keywords the learner must use in their solution.

• `Function or Keyword Is Absent` — Provide functions or keywords the learner must avoid using in their solution.

• `MATLAB Code` — Write assessments using MATLAB code. You can create inputs, call the reference and learner functions, and capture and determine correctness of the outputs. Use MATLAB code to combine multiple assessments into a single test.

Due to variable scope, assessments have access only to variables created by the test script.

3. Provide additional feedback to the learner.

MATLAB Grader provides default feedback if the solution fails the assessment. You can provide additional feedback to the learner. You can write this feedback using rich text format, including formatted text, hypertext links, images, and math equations.

4. Optionally, specify if the test is a pretest. A pretest is a test that learners can run without submitting their solution.

1. By default, assessments are not pretests.

2. To make the assessment a pretest, select Pretest.

When you make an assessment a pretest:

• When the learner clicks , MATLAB Grader runs the learner’s solution against the assessments marked as pretests and provides the instructor's feedback on those tests.

When writing pretests, keep in mind that learners can see the code used to assess pretests. You do not want to inadvertently include code needed to solve the problem in a pretest.

For assistance in how to write an assessment for a script-type problem, see Write Assessments for Script-Type Learner Solutions.

### Step 5. Save Problem

When saving the coding problem, you have two options:

• — You can continue developing this problem while it is in draft mode.

• — The problem is complete. If this problem is part of a MATLAB Grader course you are developing, the problem is viewable to learners when the course is published. Learners can view only those problems that are in the Final state. If you want to remove a problem from learner view after publishing it, open the problem and then click .

### Try an Example Script Problem

To get started with script-type problem authoring, try the example My first SCRIPT problem, which you can find in the MathWorks Collection Getting Started with MATLAB Grader.

To try solving the problem as a learner would, open the problem, click , and then click . Enter your code in the solution box and then click to run the assessments (when you perform this action in , it does not actually submit anything). Try both correct and incorrect code to see the feedback you get.