130 likes | 158 Views
Explore Matlab for technical problem-solving with vector and matrix formulation. Learn identifiers, matrices, functions, conditional statements, and graphing techniques in this tutorial.
E N D
Matlab Tutorial Iman Moazzen First Session – September 11, 2013
Matlab (Matrix Laboratory) • It allows you to solve many technical computing problems, especially those with vector or matrix formulation.
Identifiers • Variables or function names Remarks: 1- It can include letters, digits, underline 2- The first character must be a letter e.g.: 3iman iman@3 iman613 iman$$ Iman613 iman_3 pi i j
Matlab (Matrix laboratory) • Single value a=1 • Vector row vector: a=[1 2,3] column vector a=[1;2;3] • Matrix a=[1 2 3;4 5 6;7 8 9]
a=[1 4 6 7; 5 2 0 9; 8 8 3 2; 7 6 5 1] a(1,3) 6 a(1,:) [1 4 6 7] a(:,2) [4;2;8;6] a(1:3,2:3) [4 6;2 0;8 3] 2D index: a(row,column) 1D index: a(index) start:step:end e.g: 1:2:5 [1 3 5]
1D index • a(1,2) • a(6) 2 • a(1:2:end) [1 8 4 8 6 3 7 2]
Special Matrix • eye eye(3,3) • ones ones(1,3) [1 1 1] • zeros zeros(1,4) [0 0 0 0] • rand rand(1,2) [0.37 0.86] • linspace linspace(1,3,5) [1 1.5 2 2.5 3]
Basic Fucntion • + - * / ^ abs angle imag real conj round floor ceil mod min max sum prod cart2pol pol2cart syms subs exp log log10 log2 sqrt sin cos tan asin acos atan help
Use M.File to create Matlab code intead of command window • file new M.file
Conditional Statements • if-elesif-else • while • switch
Function • function [out1,out2,…]=functionname(input1,input2,…) Note: function can not be run directly, you need to call it .
Graphing • plot • color • style • Label