## Solve Problems

After signing in to MATLAB^{®}
Grader™ and selecting a course, you can find the assignments for the course in the
menu on the left. Each assignment in a course contains one or more problems. To complete
an assignment, you submit one or more correct solutions for each problem.

Before you submit your solution, you can:

Run your code to check the output (

**Run Script**or**Run Function**).Run

**Pretests**, to run the assessments the instructor has designed for a particular problem.

### Pretests

Pretests are assessments provided by your instructor that you can run without submitting your solution for grading, and are different from regular assessment tests:

When you run pretests, the pretest results are not recorded in the gradebook.

Running pretests does not count against a submission limit.

You can view the assessment code in a pretest, as well as the output generated by that code.

When you submit your solution, pretest assessments are also run and do contribute to the final grade. Pretest assessments give you a way to determine if your solution is on the right path before you submit it.

If you do not see pretests for the problem you are solving, it simply means that your instructor has not provided any.

### Solution Evaluation and Size

After you submit a solution, MATLAB Grader evaluates each solution against the assessment tests that your instructor created. MATLAB Grader determines whether your solution passes some or all of these tests. If your solution passes all of the tests for this problem, MATLAB Grader marks the solution as correct. If your solution fails one or more tests, it marks the solution as incorrect.

#### Solution Size

When you submit a solution, MATLAB Grader determines its size. MATLAB Grader uses a node-count calculation to determine the solution size based on the number of nodes in the parse tree. Think of size as code length. Writing succinct code earns you a better result.

The size of a solution has no effect on the solution score. You can, however, use the size to compare solutions and determine which solution is the best one.

#### Submission Attempt Limit

Your instructor may choose to limit the number of solutions you can submit for an assignment. If there is a submission limit, it is indicated on the solve form on the submit button, as "(Attempt X of Y)".

When there is only one submission left, you are asked to confirm the final
submission. The **Submit** button becomes disabled after you
have submitted the total allowed.

If the instructor has specified that learners may have unlimited submissions, you may submit as many solutions as you want.

#### Submission Time Limit

MATLAB
Grader enforces an execution time limit of 60 seconds. The clock starts
when you click **Run** or **Submit**, and
stops when the output or assessment results are displayed to you.

If the time limit is reached, an error message is displayed stating that the server timed out. Total execution time depends on if you are running or submitting your solution as well as if you are solving a script-based or a function-based problem.

You can get an estimate of the time required to execute the reference solution by running it using MATLAB Online™, as the computational environment used to execute the MATLAB code is most similar to what is used by MATLAB Grader.

You may find that you can see the output of your code when you click
**Run Script** or **Run Function**, but
when you submit, you get the error message "The server timed out while running
and assessing your solution." This error is due to the additional execution time
needed to evaluate the correctness of your solution.

Server time-out errors are typically the result of errors in your solution, inefficient code, or excessive output printing to the screen.

### Create a Solution

To create a solution for a problem:

Select the problem you want to solve from the list on the Assignment main page or from the menu on the left.

Review the description of the problem.

Enter your code in the Solution box. Solutions can include MATLAB functions or scripts, depending on your instructor’s requirements. Use

**Run**or**Run Function**to examine the results of your solution.Test your solution before submitting it by clicking

**Run Pretests**. Note that the option to**Run Pretests**only appears if your instructor has created pretests for a particular problem.MATLAB Grader uses the assessment tests for that problem to evaluate your solution. Check the test results to see which test cases passed or failed. Each failed test includes an error message that indicates what caused the test to fail. Tests that passed have a green check mark.

When you are satisfied with your solution, click

**Submit**. Submitting a solution allows your instructor to see it and the results of any tests for this problem. Only you and your instructor can see your submitted solutions.

#### Late Solutions

You can continue to submit solutions to problems after the assignment due date. However, you cannot be sure that the instructor is going to consider the late solutions when grading your submissions.

#### Example

Assume that a problem in one of your assignments instructs you to use a
MATLAB function to find the sum of two numbers. You can read about the
plus function in the MATLAB documentation. Using the template in the problem as your starting
point, create and test this function in the **Solution** field:

function c = add_two_numbers(a,b) %Function for Assignment 1, Problem 1 % Using plus function to add 2 numbers c = plus(a,b); end

After running your function to verify that it creates the correct output,
click **Pretests**. MATLAB
Grader uses the assessment tests to evaluate your solution and shows
whether it passed all of the tests cases.

After you have a solution that passes all assessments, click
**Submit**. After you submit the solution, your instructor
can view your code and see the results of the assessments for this
problem.

### Improve Your Solution

If you want to try to create a better solution after you solve a problem correctly, you can:

Go to the Problem page and click

**Improve Your Solution**.Enter a new solution in the Solution box, run the Pretests, and then click

**Submit**.

You can continue to enter new solutions until you find a better solution or until you reach the limit of submissions the instructor has placed on the assignment.