Week 1 Practice Questions

Lectures, code examples, and practice questions for teaching MATLAB for applications in undergraduate chemical engineering classes.

Week 1 Practice Questions

Feel free to copy the code provided into your own MATLAB scripts to check your work! Please remember that although these are answers, there are multiple ways of doing the problem(s). We encourage you to develop your own method of writing and organizing your code!

To download this file as a PDF, go here.

Basic Matrix Exercises

Please remember to comment your code and label your graphs!

  1. Define the following matrix and do the following exercises. (Each exercise should be done independently of each other)
    • Multiply each element by 3
    • Add 2 to each element
    • Isolate row 1
    • Isolate column 3
    • Divide 8 by 2 and subtract it by 5
    • Replace the 7 with your answer from e

Image of Matrix needed for problem 1

  1. Define the following additional matrix and do the following exercises with the matrix from the first exercise
    • Multiply the two matrices together (non element wise)
    • Multiply the two matrices together (element wise)
    • Add and subtract the matrices element-wise
    • Add the 3 from both matrices together
    • Multiply the entire first matrix by the second column in the second matrix. (PS: Order matters!)

Image of Matrix needed for problem 2

For Loop Exercises

  1. Create a for loop that accepts a 1xm matrix of random numbers of 0 and 1 and tells you how many elements are greater than 0.
    • You can create such a matrix by the following command: randi([0,1],n,m)
    • To find the length of a list, use the following command: length(x)

Script/Function Exercises

  1. Create a function that accepts two matrices and gives outputs for the operations done in the Live Script Exercises 1a, 1c, 1d, 2a-c, and 2e.