Chapter 2

Chapter 2 Code Examples

MATLAB

helloworld.m

Python

temp.py

Exercises

2.3.1 Basic Arithmetic

Convert the following equations into valid MATLAB or Python commands, and submit both the input and output of the command from the interpreter.

  1.  (2+3)\times7
  2.  \frac{3^3}{2}
  3.  \frac{12\times3.3^4}{1+2.7^{4.6}}

2.3.2 Creating & Editing Matrices

Create the following matrices, and submit both the input and output of the command from the interpreter.

  1. \begin{bmatrix} 4 & 6 & 2 \end{bmatrix}
  2. \begin{bmatrix} 3.5 & 3.14 \\ 7 & 0.25 \end{bmatrix}
  3. \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  4. \begin{bmatrix} 1.3 & 1.6 & 1.9 & 2.2 & 2.5 \end{bmatrix}

For the following problems, create the matrices as described, and then edit as directed, and submit the editing command and the output from the interpreter.

  1. Create the array \begin{bmatrix}1 & 2 & 3 & 4 & 5\end{bmatrix} , and replace the third element with the number 9.
  2. Create the array \begin{bmatrix}3 & 6 & 2 & 9 & 12\end{bmatrix}, and replace the second element with the value in that location cubed. That is, cube the value found in that location and store it back in the same location.
  3. Create the identity matrix and replace the element at location 2,3 with the number of elements in the identity matrix.\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

2.3.3 Saving and Loading Data

Use the materials on the book website to download the data set necessary for these problems in either MATLAB or Python.

 

  1. Load the chapter 2 data set from the zip file below (Chapter2.m or Chapter2.py). What is the value in variable “x”?
  2. Clean out the variables in your Workspace or Variable Explorer. Load the chapter 2 data set. Modify the variable “z” to equal . Save the dataset, and submit.

Chapter 2Programs

Chapter 2 MATLAB code