UcenlyOpen in the app

Mathematical Applications · BE5B15MAA · Topic 1 of 13

Introduction into Matlab: variables, vectors, matrices, complex numbers, plotting

Week 1. Type commands in the command window, build vectors and matrices, and plot one vector against another.

Open the interactive lesson

Key ideas

Command window and variables

Press Enter to run an expression: the result goes into the built-in variable ans. A trailing semicolon runs the command without printing the result. Variables need no declaration; who and whos list them, clear deletes them and clc clears the window. A complex number is written a+i*b or a+j*b.

Vectors and matrices

x=1:10:1000 builds a row vector with step 10, while linspace(from,to,count) fixes the number of points instead. Inside brackets a comma or space separates columns and a semicolon separates rows. A(row,col) indexes an element, A(2,:) is a whole row; A.' is the plain transpose, while A' is the conjugate transpose (the same for real matrices, but it also conjugates complex entries). A*B is the matrix product (the inner sizes must agree); A.*B and A.^2 work element by element, whereas A^2 means A*A.

Plotting and files

plot(x,y) draws y against x and both vectors must have the same length. Add title, xlabel, ylabel and grid on; subplot(m,n,i) splits the window into an m×n grid. Files ending in .m hold scripts and functions, .mdl are Simulink models and .mat files store variables. A sample exam task builds y=sin(x)cos(2x)e^(0.04x) for x from −2π to 2π, plots it and looks for its extremes.

In one line: A semicolon silences output, a leading dot makes an operator element-wise, and plot needs two vectors of equal length.

Formulas

Sources

Written by Ucenly. Based on the BE5B15MAA course materials: