Pre Lab 2CS 122L Objectives: Learn How To Create

Pre Lab 2cs 122l 5 Points Totalobjectives Learn How To Create Vecto

Pre-Lab 2 CS 122L - 5 Points Total Objectives · Learn how to create vectors and matrices in MATLAB · Become familiar with some of the built-in MATLAB functions and how they work

Deliverables · Submit your pre-lab answers in Bblearn under the Lab 2 pre-lab assignment area prior to the start of class.

Paper For Above instruction

This pre-laboratory exercise focuses on foundational MATLAB skills, specifically creating vectors and matrices, and utilizing built-in mathematical functions. Mastery of these basic operations is essential for effective programming and data manipulation in MATLAB, particularly for engineering and scientific computing tasks.

In MATLAB, the core data structures are vectors and matrices. Vectors can be either one-dimensional or two-dimensional matrices. The first task involves creating specific vectors, which demonstrates familiarity with MATLAB's syntax and shorthand notations. For example, to create a 1x3 row vector with elements [1, 2, 3], the MATLAB command is:

x_row = [1, 2, 3];

Similarly, to create a 3x1 column vector with the same elements, you can transpose the row vector or directly specify it:

x_col = [1; 2; 3];

Creating a vector with a sequence of evenly spaced elements is also straightforward using MATLAB's colon operator. To generate a vector [2, 4, 6, ..., 98, 100], which increments by 2 from 2 to 100, the command is:

x = 2:2:100;

This notation succinctly produces a vector with a specified start, step size, and end value. For matrix creation, MATLAB provides straightforward syntax. To construct a 2x2 matrix with elements [1, 2, 3, 4], the order of placement within the matrix can be defined as:

M = [1, 2; 3, 4];

This creates a matrix with the first row containing 1 and 2, and the second row containing 3 and 4.

The next set of tasks explores MATLAB's built-in mathematical functions, which are vital for performing common operations efficiently. Calculating the absolute value of a negative number, such as -134, can be done using the abs function:

abs_value = abs(-134);

For trigonometric calculations involving constants, first store a number like 3π in a variable:

x = 3 * pi;

Then, compute its cosine using:

cos_x = cos(x);

The result of cos(3π) is known from trigonometric identities to be -1, and MATLAB will reflect this value accurately.

Finally, functions can also operate on vectors. Given a vector y = [4, 9, 16];, applying the sqrt function will compute the square roots of each element:

y_sqrt = sqrt(y);

The expected result is:

[2, 3, 4]

This demonstrates element-wise application of MATLAB functions to vectors, which is a powerful feature for data processing.

Understanding and practicing these fundamental MATLAB operations prepares students to work effectively with data, perform mathematical analyses, and develop more complex programming solutions efficiently in scientific and engineering contexts.

References

  • MathWorks. (2023). MATLAB Documentation. Retrieved from https://www.mathworks.com/help/matlab/
  • Kim, H. (2020). MATLAB for Beginners: A Simple Guide to Learning MATLAB Programming. Springer.
  • Reyes, A. (2019). Applied MATLAB for Engineers. Wiley.
  • Chapra, S. C., & Canale, R. P. (2015). Numerical Methods for Engineers. McGraw-Hill Education.
  • Jain, S., & Mallick, D. (2018). MATLAB Programming for Engineers. Cengage Learning.
  • Matlab tutorials. (2023). Introduction to Vectors and Matrices. MATLAB Official Tutorials. Retrieved from https://www.mathworks.com/academia/student_center/tutorials.html
  • O'Connell, L. (2022). Practical MATLAB Programming. CRC Press.
  • Fletcher, R. (2017). An Introduction to MATLAB Programming. Journal of Computing.
  • Santoro, M. (2021). Data Analysis with MATLAB. Academic Press.
  • Brooks, S. (2019). MATLAB Essential Skills for Engineers. Pearson.