Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MATLAB Fundamentals - Cheat Sheet, Study notes of Linear Algebra

MATLAB Fundamentals - Cheat Sheet - Tools Course ETH Zürich. Basics. Workspace ans. Most recent answer clc clear command window clear var.

Typology: Study notes

2021/2022

Uploaded on 08/05/2022

jacqueline_nel
jacqueline_nel 🇧🇪

4.4

(229)

506 documents

Partial preview of the text

Download MATLAB Fundamentals - Cheat Sheet and more Study notes Linear Algebra in PDF only on Docsity! MATLAB Fundamentals - Cheat Sheet - Tools Course ETH Zürich Basics Workspace ans Most recent answer clc clear command window clear var clear variables Workspace clf Clear all plots close all Close all plots ctrl-c Kill the current calculation doc fun open documentation disp(’text’) Print text format short—long Set output display format help fun open in-line help load filename {vars} load variables from .mat file save {-append} file {vars} save var to file addpath path include path to .. iskeyword arg Check if arg is keyword % This is a comment Comments ... connect lines (with break) ";" (after command) suppresses output scriptname runs scriptname.m tic, toc start and stop timer ver List of installed toolboxes MATLAB Documentation: mathworks.com/help/matlab/ Defining and Changing Variables a = 5 Define variable a to be 5 A = [1, 2, 3, 4; Set A to be a 3× 4 matrix 5, 6, 7, 8; ”,” separates columns 9, 10, 11, 12] ”;” separates rows [A,B], horzcat(A,B) Concatenate arrays horizontally [A;B], vertcat(A,B) Concatenate arrays vertically x(2) = 7 Change 2nd element of x to 7 A(2,1) = 0 Change A2,1 to 0 x(2:12) The 2nd to the 12th elem. of x x(1:3:end) Every 3rd elem. of x (1st to last) x(x>6) List elements > 6. x(x>8)=8 change elements using condition A(4,:) Get the 4th row of A A(:,3) Get the 3rd column of A A(6, 1:3) Get 1st to 3rd elem in 6th row zeros(9, 5) Make a 9× 5 matrix of zeros ones(9, 5) Make a 9× 5 matrix of ones eye(7) Make a 7× 7 identity matrix diag(x) Create diagonal matrix diag(A) Get diagonal elements of matrix meshgrid(x) 2-D and 3-D grids 7:15 Row vector of 7, 8, . . . , 14, 15 a:ds:b lin. spaced vector with spacing ds linspace(1,20,35) Lin. spaced vector (35 elements) logspace(1, 1e5, 50) Log. spaced vector (50 elements) Arithmetics +, - Addition, Subtraction (elementwise) A*B Matrix multiplication A.*B elementwise multiplication A./B elementwise division B.\A Left array division / Solve xA = B for x \ Solve Ax = B for x A∧n normal/(square) matrix power A.∧n Elementwise power of A sum(X) Sum of elements (along columns) prod(X) Product of elements (along columns) Elementary Functions sin(A) Sine of argument in radians sind(A) Sine of argument in degrees asin(A) Inverse sine in radians sinh(A) Hyperbolic sine there are analogous elementwise trigonometric functions for cos, tan and cot abs(A) Compute |x| sqrt(x) Compute √ x log(x) Compute ln(x) log10(x) Compute log10(x) sign(x) sign of x exp(x) exponential of x Complex Numbers abs(z) Absolute value and complex magnitude angle(z) Phase angle complex(a,b) Create complex numbers conj(z) Elementwise complex conjugate i or j Imaginary unit imag(z) Imaginary part of complex number isreal(z) Determine whether array is real real(z) Real part of complex number ctranspose(Z) Complex conjugate transpose Constants pi π = 3.141592653589793 NaN Not a number (i.e. 0/0) Inf Infinity eps Floating-point relative accuracy realmax Largest positive floating-point number realmin Smallest positive floating-point number Numerics and Linear Algebra Numerical Integration and Differentiation integral(f,a,b) Numerical integration integral2(f,a,b,c,d) 2D num. integration integral3(f,a,b,..,r,s) 3D num. integration trapz(x,y) Trapezoidal integration cumtrapz(x,y) Cumulative trapez integration diff(X) Differences (along columns) gradient(X) Numerical gradient Matrix Functions/ Linear Algebra A’ Transpose of matrix or vector inv(A) inverse of A (use with care!) det(A) determinant of A eig(A),eigs(A) eigenvalues of A (subset) cross(A,B) Cross product dot(A,B) Dot product kron(A,B) Kronecker tensor product norm(x) Vector and matrix norms linsolve(A,B) Solve linear system of equations rank(A) Rank of matrix trace(A) Sum of diagonal elements curl(X,Y,Z,U,V,W) Curl and angular velocity divergence(X,..,W) Compute divergence of vector field null(A) Null space of matrix orth(A) Orthonormal basis for matrix range mldivide(A,B) Solve linear system Ax = B for x mrdivide(B,A) Solve linear system xA = B for x decomposition(A) Matrix decomposition lsqminnorm(A,B) Least-squares solution to linear eq. rref(A) Reduced row echelon form balance(A) Diagonal scaling (improve eig. vec.) svd(A) Singular value decomposition gsvd(A,B) Generalized svd chol(A) Cholesky factorization Matrix manipulation cat(dim,A,B) Concatenate arrays ndims(A) Number of array dimensions flip(A) Flip order of elements fliplr(A) Flip array left to right flipud(A) Flip array up to down squeeze(A) Remove dimensions of length 1 reshape(A,sz) Reshape array size(A) size of A sort(A) Sort array elements sortrows(A) Sort rows of matrix or table length(A) Length of largest array dimension Cheat Sheet for MATLAB Tools Course at ETH Zürich, by Res Jöhr
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved