The document you are currently reading is a MATLAB Live Script. Live scripts are interactive documents that combine MATLAB code with formatted text, equations, and images in a single interactive environment called the MATLAB Live Editor. In this context you can see your results together with the code that produced them.

In the following sections you will learn

- How to run, edit and create code with the Live Editor,
- How to use common operators for basic calculations with numbers,
- How to define variables to store numbers and perform calculations.

Each Live Script is divided in sections that may contain code. Each section can be run individually.

To run the code from each section, click into the code section and then click on the Run Section button (from the toolstrip) or click on the blue stripe on left side of that section as shown below:

Remark: Run the code of each section from top to bottom, otherwise you may get an error.

- The end of a section is indicated with a thin line, like the next one -

In the Live Script the MATLAB code is inside a grey square as the example below which shows the use of the operators +, -, /, * , ^, () for basic calculations with numbers:

5.5 + 3 % Addition

2 - 1.3 % Subtraction

8 / 2 % Division

2 * 5 % Multiplication

2^3 % Exponentiation

(3 * 2 - 2) * 2 % Brackets

When you run this section, you will notice that the output appears together with the code inside the live editor. Try it, run this section!

If you click on an output value, the cursor shows you which line of code produced that output as shown image below:

You can also display your output inline:

To change the output displays, use the icons on the right-side window of the Live Editor:

Errors in the code will appear next to the line where they occur:

The following code has three errors. Run this section to find them. Then fix the errors in the code and re-run it.

a = pi; % Constant pi

b = sqrt(2); % Square root of 2

c = sin(0); % Trig function sin evaluated at 0

op = cos(a / 2) + b + c

Remark: Every time you modify your code a hatch blue bar appears on the left side. This tells you that you have modified the code. To run the latest version just click on this bar.

Finally, if you want to clear all the Outputs, right click in any section to open the help menu. Then select the option

Let's practice what we just learned.

In section 1.1 we introduced the operators +, -, /, *, ^, () for simple calculations with numbers. In section 1.2 we used the built-in constant pi and the functions sqrt(), sin() and cos().

Use these operators and functions to calculate the following:

Write your code here and run it:

We can define variables to store numbers and operate with them. Variable names consist of a letter followed by any number of letters, digits or underscore. For example:

x = 3;

y_0 = 2;

y_1 = 5;

initial_value = 0;

z0 = x + y_0 * y_1 + initial_value / 2

Remark: Notice that at the beginning of the previous code, the semicolon ";" was added at the end. In general, a semicolon indicates end of statement. However, if you want to suppress and hide the MATLAB output for an expression, you must add a semicolon after the expression. Modify the code to suppress on the output the variables y_0, y_1 and initial_value. Then re-run the code.

A model for the velocity of a falling object after time t is given by

where m is the mass of the object in , is the acceleration due to gravity, k is a constant, t is measured in seconds, and v in .

If a person falls from a building, the value of the constant k depends on his or her position. For a "belly-to-earth" position, , but for a "feet-first" position, .

Problem 1: What is the velocity of a 60-kg person falling in belly-to-earth position after 10 seconds and after 30 seconds? What if he/she falls in feet-first position?

Write your code here:

% define variabes

% belly-to-earth velocity

% feet-first velocity

The terminal velocity of a falling object is determined by the limit

Problem 2: Calculate this limit on your notebook and then use MATLAB to compute the terminal velocity of a 60-kg person falling in belly-to-earth and feet-first position.

Write your code here:

% belly-to-earth terminal velocity

% feet-first terminal velocity

Hint: Recall that .

Analyse your results and compare them with the results from Problem 1. What do you notice? What do you wonder?

Long, L, N. & Weiss, H. (2006). How terminal is terminal velocity? The American Mathematical Monthly. (113): 752-755.