Outline. 1. Introduction to MATLAB 2. Symbolic Toolbox 3. Plots 4. Calculus 5. matrices and vectors 6. M-files 7. Programming 8.

Size: px
Start display at page:

Download "Outline. 1. Introduction to MATLAB 2. Symbolic Toolbox 3. Plots 4. Calculus 5. matrices and vectors 6. M-files 7. Programming 8."

Transcription

1 MATLAB

2 Outline 1. Introduction to MATLAB 2. Symbolic Toolbox 3. Plots 4. Calculus 5. matrices and vectors 6. M-files 7. Programming 8. simulink

3 1. INTRODUCTION

4 Introduction MATLAB stands for MATrix LABoratory Initially developed by a lecturer in 1970 s to help students learn linear algebra. Everything is a matrix - easy to do linear algebra It was later marketed and further developed under MathWorks Inc. (founded in 1984) Matlab is a software package which can be used to perform analysis and solve mathematical and engineering problems High level language for technical computing It has excellent programming features and graphics capability easy to learn and flexible. Available in many operating systems Windows, Macintosh, Unix, DOS It has several toolboxes to solve specific problems.

5 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for us How high? Matlab High Level Languages such as C, Pascal, Fortran etc. Assembly language

6 Why Matlab? Common Uses for Matlab in Research Mathematical computations Data Acquisition Multi-platform, multi-format data importing Analysis Tools (existing,custom) Statistics Graphing Modeling Used a lot for problem solving Cybernetics Signal processing Image processing Pattern recognition

7 Why Matlab? Multi-platform, Multi Format data importing Data can be loaded into Matlab from almost any format and platform Binary data files (eg. REX, PLEXON etc.) Ascii Text (eg. Eyelink I, II) Analog/Digital Data files PC UNIX Subject Subject Subject 3 87

8 Analysis Tools Why Matlab? A considerable library of analysis tools exist for data analysis Provides a framework for the design, creation, and implementation of any custom analysis tool imaginable

9 Why Matlab? Graphing, Visualization A Comprehensive array of plotting options available from 2 to 4 dimensions Full control of formatting, axes, and other visual representational elements

10 Why Matlab? Modeling Models of complex dynamic system interactions can be designed to test experimental data

11 Strengths of MATLAB MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to fix Although primarily procedural, MATLAB does have some object-oriented elements

12 No need for types. i.e., int a; double b; float c; Variables All variables are created with double precision unless specified and they are matrices. Example: >>x=5; >>x1=2; After these statements, the variables are 1x1 matrices with double precision

13 Weaknesses of MATLAB MATLAB is NOT a general purpose programming language MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientific computation and is not suitable for some things (such as parsing text)

14 Where to get MATLAB Mathworks: Student version is affordable and complete.

15 The MATLAB System Development Environment Mathematical Function Library MATLAB language Application Programming Language (not discussed today)

16 Menu and toolbar MATLAB Desktop Workspace History Command

17 Matlab Screen Command Window type commands Current Directory View folders and m-files Workspace View program variables Double click on a variable to see it in the Array Editor Command History view past commands save a whole session using diary

18 User interface Command window Workspace Editor Help

19 Workspace User interface

20 Editor User interface

21 Help Contents Index Search Demo User interface Type help help function, e.g. help plot Running demos type demos type help demos Using the Help Browser (.html,.pdf) View getstart.pdf, graphg.pdf, using_ml.pdf

22 Useful Commands The two commands used most by Matlab users are >>help functionname >>lookfor keyword Keep a diary of your work >>Diary >> >> >>Diary off

23 File I/O Matlab has a native file format to save and load workspaces. Use keywords load and save. In addition MATLAB knows a large number of popular formats. Type help fileformats for a listing. In addition MATLAB supports C style low level file I/O. Type help fprintf for more information.

24 Note % is the neglect sign for Matlab (equivalent of // in C). Anything after it on the same line is neglected by Matlab compiler. Insert comment lines, starts with %, so that you understand your program Sometimes slowing down the execution is done deliberately for observation purposes. You can use the command pause for this purpose pause %wait until any key pause(3) %wait 3 seconds

25 Workspace Matlab remembers old commands and variables as well each function maintains its own scope the keyword clear removes all variables from workspace the keyword who lists the variables

26 Some Key Commands Executing Commands Basic Calculation Operators: + Addition - Subtraction * Multiplication / Division ^ Exponentiation

27 Order of computations to the power of multiplication, division subtraction, addition If you want to change the priorities use brackets

28 Number format Short: 4 digits Long: 14 digits round-off errors may become significant If you carry out more complex computations

29 2. Symbolic Math Toolbox

30 What is Symbolic Math? Symbolic mathematics deals with equations before you plug in the numbers. Calculus integration, differentiation, Taylor series expansion, Linear Algebra inverses, determinants, eigenvalues, Simplification algebraic and trigonometric expressions Equation Solutions algebraic and differential equations Transforms Fourier, Laplace, Z transforms and inverse transforms, You must use syms to declare the variables you plan to use to be symbolic variables

31 Matlab's Symbolic Toolbox The Symbolic Toolbox allows one to use Matlab for symbolic math calculations. The Symbolic Toolbox is a separately licensed option for Matlab. (The license server separately counts usage of the Symbolic Toolbox.) Recent versions use a symbolic computation engine called MuPAD. Older versions used Maple. Matlab translates the commands you use to work with the appropriate engine. One could also use Maple or Mathematica for symbolic math calculations. Strategy: Use the symbolic toolbox only to develop the equations you will need. Then use those equations with nonsymbolic Matlab to implement your program.

32 Symbolic Objects Use sym to create a symbolic number, and double to convert to a normal number. >> sqrt(2) ans = >> var = sqrt(sym(2)) var = 2^(1/2) >> double(var) ans = >> sym(2)/sym(5) + sym(1)/sym(3) ans = 11/15

33 Symbolic variables Use syms to define symbolic variables. (Or use sym to create an abbreviated symbol name.) >> syms m n b c x >> th = sym('theta') >> sin(th) ans = sin(theta) >> sin(th)^2 + cos(th)^2 ans = cos(theta)^2 + sin(theta)^2 >> y = m*x + b y = b + m*x

34 Substituting into symbolic expressions The subs function substitutes values or expressions for variables in a symbolic expression. >> clear >> syms m x b >> y = m*x + b y = b + m*x >> subs(y,x,3) ans = b + 3*m >> subs(y, [m b], [2 3]) ans = 2*x + 3 >> subs(y, [b m x], [3 2 4]) ans = 11 The symbolic expression itself is unchanged. >> y y = b + m*x

35 Substitutions, continued Variables can hold symbolic expressions. >> syms th z >> f = cos(th) f = cos(th) >> subs(f,pi) ans = -1 Expressions can be substituted into variables. >> subs(f, z*pi) ans = cos(pi*z)

36 Differentiation Use diff to do symbolic differentiation. >> clear >> syms m x b th n y >> y = m*x + b; >> diff(y, x) ans = m >> diff(y, b) ans = 1 >> p = sin(th)^n p = sin(th)^n >> diff(p, th) ans = n*cos(th)*sin(th)^(n - 1)

37 Integration >> clear >> syms m b x >> y = m*x + b; Indefinite integrals >> int(y, x) ans = (m*x^2)/2 + b*x >> int(y, b) ans = (b + m*x)^2/2 >> int(1/(1+x^2)) ans = atan(x) Definite integrals >> int(y,x,2,5) ans = 3*b + (21*m)/2 >> int(1/(1+x^2),x,0,1) ans = pi/4

38 Solving algebraic equations >> clear >> syms a b c d x >> solve('a*x^2 + b*x + c = 0') ans = % Quadratic equation! -(b + (b^2-4*a*c)^(1/2))/(2*a) -(b - (b^2-4*a*c)^(1/2))/(2*a) >> solve('a*x^3 + b*x^2 + c*x + d = 0') Nasty-looking expression >> pretty(ans) Debatable better-looking expression Another example: >> solve('m*x + b - (n*x + c)', 'x') ans = -(b - c)/(m - n) >> solve('m*x + b - (n*x + c)', 'b') ans = c - m*x + n*x >> collect(ans, 'x') ans = c - x*(m - n)

39 Solving systems of equations Systems of equations can be solved. >> [x, y] = solve('x^2 + x*y + y = 3',... 'x^2-4*x + 3 = 0') Two solutions: x = [ 1 ; 3 ] y = [ 1 ; -3/2 ] >> [x, y] = solve('m*x + b = y', 'y = n*x + c') Unique solution: x = -(b - c)/(m - n) y = -(b*n - c*m)/(m - n) If there is no analytic solution, a numeric solution is attempted. >> [x,y] = solve('sin(x+y) - exp(x)*y = 0',... 'x^2 - y = 2') x = y =

40 Solving differential equations We want to solve: Use D to represent differentiation against the independent variable. >> y = dsolve('dy = -a*y') y = C5/exp(a*t) Initial values can be added: >> y = dsolve('dy = -a*y', 'y(0) = 1') y = 1/exp(a*t)

41 Simplifying expressions >> clear; syms th >> cos(th)^2 + sin(th)^2 ans = cos(th)^2 + sin(th)^2 >> simplify(ans) ans = 1 >> simple(cos(th)^2 + sin(th)^2) >> [result,how] = simple(cos(th)^ sin(th)^2) result = 1 how = simplify >> [result,how] = simple(cos(th)+i*sin(th)) result = exp(i*th) how = rewrite(exp)

42 3. Plotting Graphs

43 Many Options Matlab has a powerful plotting engine (built in functions) that can generate a wide variety of plots. 2-D plots, 3-D plots, contour plots, line plots, polar plots

44 Use the help command and you find the built in functions >>> help graph2d >>> help graph3d e.g. plot polar loglog mesh semilog plotyy surf

45 Graphics: 2D-plotting Example: y=f(x) with f(x) = x 2 Plot f(x) in the interval x [-2,2].

46 Another Example: Plot the function e -x/3 sin(x) between 0 x 4π Create an x-array of 100 samples between 0 and 4π. >>x=linspace(0,4*pi,100); Calculate sin(.) of the x-array >>y=sin(x); Calculate e -x/3 of the x-array >>y1=exp(-x/3); Multiply the arrays y and y1 >>y2=y*y1; THIS IS WRONG!!!

47 Plot the function e -x/3 sin(x) between 0 x 4π Multiply the arrays y and y1 correctly by using the. command 0.7 >>y2=y.*y1; Plot the y2-array >>plot(y2)

48 Data visualisation plotting graphs Example on plot 2 dimensional plot >>> x=linspace(0,(2*pi),100); >>> y1=sin(x); >>> y2=cos(x); >>> plot(x,y1,'r-') >>> hold Current plot held >>> plot(x,y2,'g--') >>> Add title, labels and legend title xlabel ylabel legend You can add to the plot by using copy and paste (if you copy the plot into e.g. MSWord. You can also insert titles, labels, legends by using commands in the plot environment

49 y1 and y2 Data visualisation plotting graphs Example on plot sin(x) cos(x) angular frequency (rad/s)

50 Graphics - Annotation

51 Use title, xlabel, Graphics - Annotation ylabel and legend for annotation >> title('demo plot'); >> xlabel('x Axis'); >> ylabel('y Axis'); >> legend([pl1, pl2], 'x^2', 'x^3');

52 Graphics: Multiple Graphs in One Plot Window >>t = 0:pi/100:2*pi; >>y1=sin(t); >>y2=sin(t+pi/2); >>plot(t,y1,t,y2) >>grid on

53 Graphics: Multiple Plots The command subplot(m,n,o) devides the plotting window into several panes. The command defines a matrix of n plots in rows 1 m, whereby o defines the position of the subplots >>t = 0:pi/100:2*pi; >>y1=sin(t); >>y2=sin(t+pi/2); >>subplot(2,2,1) >>plot(t,y1) >>subplot(2,2,2) >>plot(t,y2) The commands >>subplot (2,2,3) and >>subplot (2,2,4) generate two more plots in 2 nd row

54 Graphics: plotting symbolic expressions The ezplot function will plot symbolic expressions. >> clear; syms x y >> ezplot( 1 / (5 + 4*cos(x)) ); >> hold on; axis equal >> g = x^2 + y^2-3; >> ezplot(g); use >>hold on For overlaying graphs

55 Graphics: 3D plots Plot a surface function of z= e -x2 -y 2 over the square [-2,2] x [-2,2] Compute a grid of points that can be plotted >> x=-2:.2:2; >> y=-2:.2:2; >> [X,Y]=meshgrid(x,y); >>z=exp(-x.^2-y.^2); >>mesh(z) >>xlabel( x ); >>ylabel( y ); >>zlabel( z ); >>titel( example of a 3D-meshplot) Example of a 3D-meshplot

56 Difference between ezplot and plot You do not need to use ezplot. You can also use the command plot The fundamental difference: The command ezplot uses intrinsically a useful stepsize to plot a graph If you use the plot command you must define the step size (increment) yourself Step size means: you define the number of points N that you want to plot You must define the increment, which is defined by h=1/n You must define the range for which you want to plot the graph: x from minimum value to maximum value

57 How to save plots use saveas(h,'filename.ext') to save a figure/file. >> f=figure; >> x=-5:0.1:5; >> h=plot(x,cos(2*x+pi/3)); >> title('figure 1'); >> xlabel('x'); >> saveas(h,'figure1.fig') >> saveas(h,'figure1.eps ) Useful extension types: bmp: Windows bitmap emf: Enhanced metafile eps: EPS Level 1 fig: MATLAB figure Useful extension types: jpg: JPEG image m: MATLAB M-file tif: TIFF image, compressed

58 4. Calculus: examples

59 Calculus Operations with MATLAB A digital computer operates on a numerical basis with addition, subtraction, multiplication, and division, along with memory storage and logic. True differentiation and integration can never be achieved exactly with numerical processes. However, there are two ways that differentiation and integration can be achieved on a practical level with MATLAB.

60 Two Types of Operations 1) MATLAB can be viewed as a very comprehensive "look-up" table in that numerous derivatives and integrals as character strings can be manipulated with software. The Symbolic Math Toolbox permits the exact formulas for derivatives and integrals to be extracted, manipulated, and plotted.

61 Two Types of Operations (Continued) 2) MATLAB can be used for calculus with numerical approximations to differentiation and integration. While such approximations are not exact, they can be used to provide extremely close approximations to the derivatives and integrals of experimental data, even when closed form solutions are impossible.

62 Symbolic Variables A symbolic variable is one that can be manipulated in the same manner as in an equation, and it may or may not ever take on any numerical values. To make x and a symbolic, the command is >> syms x a Alternately, the symbolic portion of a command may be enclosed with apostrophes ' '.

63 Symbolic Differentiation The command is diff( ) with the function to be differentiated in parentheses. All variables should have been established as symbolic variables or the function should be enclosed by apostrophes.

64 Determine the derivative of the function y >> syms x >> y = 4*x^5 y = 4*x^5 >> yprime = diff(y) >> yprime = 20*x^4

65 Continuation: second approach >> yprime = diff(4*x^5) >> yprime = 20*x^4

66 Continuation: third approach >> y = '4*x^5' y = 4*x^5 >> yprime = diff(y) >> yprime = 20*x^4

67 Continuation The third approach could also be performed in one step. >> yprime = diff('4*x^5') >> yprime = 20*x^4

68 Example: Use ezplot to plot y and yprime of the previous example The simplest form is ezplot(y), but the domain will be from -2 to 2. The domain can be changed by >> ezplot(y, [x1 x2]) In this example, ezplot(y, [-1 1]) ezplot(yprime,[-1 1]) The plots after labeling are shown on the next two slides.

69

70

71 Symbolic Integration The command is int( ) with the function to be integrated in parentheses. All variables should have been established as symbolic variables or the function should be enclosed by apostrophes. Indefinite Integral: >> yint = int(y) Definite Integral: >> yint = int(y, a, b)

72 Determine the integral of the function y >> syms x >> y = x^2*exp(x) y = x^2*exp(x) >> z = int(y) z = x^2*exp(x)-2*x*exp(x)+2*exp(x)

73 Continuation We require that z(0) = 0, but the function obtained has a value of 2 at x = 0. Thus, >> z = z - 2 z = x^2*exp(x)-2*x*exp(x)+2*exp(x)-2 Plots of y and z are shown on the next two slides.

74

75

76 Numerical Differentiation Generally, numerical differentiation is more prone to error than numerical integration due to the nature of sudden changes in differentiation. dy dx y x

77 Diff Command for Numerical Data Assume that x and y have been defined at N+1 points. A vector u with N points is defined as u y y u y y u y y u y y N N 1 N

78 Diff Command for Numerical Data, continuation The following command forms u: >> u = diff(y) The approximate derivative, >> yprime = diff(y)/delx Because x and y have one more point than yprime, they can be adjusted. >> x = x(1:n) >> y = y(1:n) >> plot(x, y, x, yprime)

79 For y = sin x, determine the numerical derivative based on 11 points in one cycle >> x = linspace(0, 2*pi, 11); >> y = sin(x); >> delx = 2*pi/10; >> yprime = diff(y)/delx; >> x = x(1:10); >> plot(x, yprime, x, cos(x), o ) The plots are shown on the next slide. The approximation is crude as expected.

80

81 For y = sin x, determine the numerical derivative based on 101 points in one cycle >> x = linspace(0, 2*pi, 101); >> y = sin(x); >> delx = 2*pi/100; >> yprime = diff(y)/delx; >> x = x(1:100); >> plot(x, yprime, x, cos(x), o ) The plots are shown on the next slide. The approximation is much better.

82

83 Numerical Integration Two types will be studied: 1. Zero-order integration 2. First-order integration, which is also known as the trapezoidal rule. Assume vectors x and y that have each been defined at N points.

84 Zero-Order Integration z z y x ( y y ) x z z y x ( y y y ) x z 1 y1 x z z y x y x k k 1 k n n 1 k

85 Two Zero-Order MATLAB Commands The two MATLAB commands for zero-order integration are sum() and cumsum(). >> area = delx*sum(y) >> z = delx*cumsum(y)

86 Two First-Order MATLAB Commands The two MATLAB commands for first-order integration are trapz() and cumtrapz(). >> area = delx*trapz(y) >> z = delx*cumtrapz(y)

87 Example: determine the exact area A for the following integral A x dx A 4 4x 4 2 x (2) 4 (0)

88 Determine the approximate area A1 with the zero-order integration algorithm and step-size of 0.05 >> delx = 0.05; >> x = 0:delx:2; >> y = 4*x.^3; >> A1 = delx*sum(y) A1 =

89 Determine the approximate area A2 with the first-order integration algorithm and step-size of 0.05 >> delx = 0.05; >> x = 0:delx:2; >> y = 4*x.^3; >> A2 = delx*trapz(y) A2 =

90 Determine the exact running integral for the following function z x sin 0 xdx z cos x x 0 cos x ( cos0) 1 cos x

91 Determine first-order approximations with 100 points per cycle and plot the two functions >> delx = 2*pi/100; >> x = 0:delx:2*pi; >> y = sin(x); >> z1 = delx*cumtrapz(y); >> plot(x, z1, x, 1 - cos(x), o ) The plots are shown on the next slide

92

93 5. Matrices and Vectors

94 Basic functions Create matrices Matrix operations Matrix functions Matrix indexing Logical operations

95 Working with Matrices Matlab works with essentially only one kind of object, a rectangular numerical matrix A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns The number of rows and columns can be any number Example 3 rows and 4 columns define a 3 x 4 matrix having 12 elements A scalar is a single number and is represented by a 1 x 1 matrix in matlab. A vector is a one dimensional array of numbers and is represented by an n x 1 column vector or a 1 x n row vector of n elements

96 Using Matlab Solving equations using variables Matlab is an expression language Expressions typed by the user are interpreted and evaluated by the Matlab system Variables are names used to store values Variable names allow stored values to be retrieved for calculations or permanently saved >> x = 6 >> x * y Variable = Expression Or Expression x = 6 >> y = 2 y = 2 >> x + y Ans = 12 >> x / y Ans = 3 >> x ^ y **Variable Names are Case Sensitive! Ans = 8 Ans = 36

97 Matrices & Vectors All (almost) entities in MATLAB are matrices Easy to define: >> A = [16 3; 5 10] A = Use, or to separate row elements -- use ; to separate rows

98 Order of Matrix - Matrices & Vectors m n m=no. of rows, n=no. of columns Vectors - special case n = 1 column vector m = 1 row vector

99 Creating Vectors and Matrices Define Transpose >> A = [16 3; 5 10] A = >> B = [ ] B = Vector : >> a=[1 2 3]; >> a' Matrix: >> A=[1 2; 3 4]; >> A' ans =

100 Variables Vectors and Matrices ALL variables are matrices e.g. 1 x 1 Variables 4 x 1 1 x 4 2 x They are case sensitive i.e x X Their names can contain up to 31 characters Must start with a letter Variables are stored in workspace

101 Some built-in functions mean(a) mean value of a vector max(a) maximum value of a vector element min(a) minimum value of a vector element sum(a) summation of the elements of A sort(a) sorted vector median(a) median value std(a) standard deviation det(a) determinant of a square matrix dot(a,b) dot product of two vectors cross(a,b) cross product of two vectors inv(a) inverse of a matrix A

102 Arithmetic Operators + addition - subtraction * multiplication / division \ left division. The operation A\B is effectively the same as INV(A)*B, although left division is calculated differently and is much quicker ^ exponentiation transponation complex conjugate transpose.* element wise multiplication./ element wise division.^ element wise power

103 Basic Operations: create matrices 1) column vector 2) row vector 3) scalar 4) matrix

104 Basic functions: matrix operators

105 Matrix indexing Basic functions

106 Matrix Operations Indexing Matrices [ A = [ The colon operator can be used to remove entire rows or columns Specify an element of a matrix >> A(:,3) = [ ] [ A = [ >> A(2,:) = [ ] [ A = [

107 Creating Matrices: built in functions zeros(m, n) matrix with all zeros ones(m, n) matrix with all ones. eye(m, n) the identity matrix rand(m, n) uniformly distributed random randn(m, n) normally distributed random magic(m) square matrix whose elements have the same sum, along the row, column and diagonal pascal(m) Pascal matrix length(m) computes the length of a vector size(m) determines the dimension of a matrix : automatic generation

108 How do we assign values to matrices? >>> A=[1 2 3;4 5 6;7 8 9] A = >>> Columns separated by space or a comma Rows separated by semi-colon

109 How do we access elements in a matrix or a vector? Try the followings: >>> A(2,3) ans = 6 >>> A(1,:) ans = >>> A(:,3) ans = >>> A(2,:) ans = 4 5 6

110 Vectors and Matrices Some special variables >>> 1/0 beep pi ( ) inf (e.g. 1/0) i, j ( 1 ) Warning: Divide by zero. ans = Inf >>> pi ans = >>> i ans = i

111 Arithmetic operations Matrices Performing operations to every entry in a matrix >>> A=[1 2 3;4 5 6;7 8 9] A = >>> Add and subtract >>> A+3 ans = >>> A-2 ans =

112 Arithmetic operations Matrices Performing operations to every entry in a matrix >>> A=[1 2 3;4 5 6;7 8 9] A = >>> Multiply and divide >>> A*2 ans = >>> A/3 ans =

113 Arithmetic operations Matrices Performing operations to every entry in a matrix >>> A=[1 2 3;4 5 6;7 8 9] A = >>> A^2 = A * A Power To square every element in A, use the element wise operator.^ >>> A.^2 ans = >>> A^2 ans =

114 Array Operations Evaluated element by element.' : array transpose (non-conjugated transpose).^ : array power.* : array multiplication./ : array division Very different from Matrix operations >> A=[1 2;3 4]; >> B=[5 6;7 8]; >> A*B But: >> A.*B

115 Vectors and Matrices Arithmetic operations Matrices Performing operations between matrices >>> A=[1 2 3;4 5 6;7 8 9] A = >>> B=[1 1 1;2 2 2;3 3 3] B = A*B = A.*B 1x1 4x2 7x3 2x1 5x2 8x3 3x1 6x2 9x3 =

116 Arithmetic operations Matrices Performing operations between matrices A/B? (matrices singular) A./B 1/1 4 / 2 7 / 3 2 /1 5 / 2 8 / 3 3 /1 6 / 2 9 / 3 =

117 Arithmetic operations Matrices Performing operations between matrices A^B??? Error using ==> ^ At least one operand must be scalar A.^B =

118 Matrix Operations Shortcut: Transposing Matrices The transpose of a matrix is the matrix formed by interchanging the rows and columns of a given matrix A = [ B = [ ] 7 3 3] >> transpose(a) >> B A = [1 6 B = [ ] ]

119 Built in functions (commands) Scalar functions used for scalars and operate element-wise when applied to a matrix or vector e.g. sin cos tan atan asin log abs angle sqrt round floor At any time you can use the command help to get help e.g. >>>help sin

120 Built in functions (commands) >>> a=linspace(0,(2*pi),10) a = Columns 1 through Columns 8 through >>> b=sin(a) b = Columns 1 through Columns 8 through >>>

121 Built in functions (commands) Vector functions operate on vectors returning scalar value e.g. max min mean prod sum length >>> a=linspace(0,(2*pi),10); >>> b=sin(a); >>> max(b) ans = >>> max(a) ans = >>> length(a) ans = >>> 10

122 Built in functions (commands) Matrix functions perform operations on matrices >>> help elmat >>> help matfun e.g. eye size inv det eig At any time you can use the command help to get help

123 Built in functions (commands) Matrix functions perform operations on matrices >>> x=rand(4,4) x = >>> xinv=inv(x) xinv = >>> x*xinv ans = >>>

124 Adding Elements to a Vector or a >> A=1:3 A= >> A(4:6)=5:2:9 A= >> B=1:2 B= 1 2 >> B(5)=7; B= Matrix >> C=[1 2; 3 4] C= >> C(3,:)=[5 6]; C= >> D=linspace(4,12,3); >> E=[C D ] E=

125 Long Array, Matrix t =1:10 t = k =2:-0.5:-1 k = B = [1:4; 5:8] x =

126 Creating Vectors Create vector with equally spaced intervals >> x=0:0.5:pi x = Create vector with n equally spaced intervals >> x=linspace(0, pi, 7) x = Equal spaced intervals in logarithm space >> x=logspace(1,2,7) x = Note: MATLAB uses pi to represent imaginary unit, uses i or j to represent

127 Generating Vectors from functions zeros(m,n) MxN matrix of zeros ones(m,n) MxN matrix of ones rand(m,n) MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x = x = ones(1,3) x = x = rand(1,3) x =

128 Concatenation of Matrices x = [1 2], y = [4 5], z=[ 0 0] A = [ x y] B = [x ; y] C = [x y ;z] Error:??? Error using ==> vertcat CAT arguments dimensions are not consistent.

129 The use of. Element A = [1 2 3; 5 1 4; 3 2 1] A = Operation x = A(1,:) x= y = A(3,:) y= b = x.* y b= c = x. / y c= d = x.^2 d= K= x^2 Erorr:??? Error using ==> mpower Matrix must be square. B=x*y Erorr:??? Error using ==> mtimes Inner matrix dimensions must agree.

130 6. m-files

131 Solution : use M-files M-files : Script and function files When problems become complicated and require re evaluation, entering command at MATLAB prompt is not practical Script Collections of commands Executed in sequence when called Saved with extension.m Function User defined commands Normally has input & output Saved with extension.m

132 There are script m-files and function m-files The difference is: Script m-files do exactly and only what you write in the script files. They are NOT interactive!!!

133 From function to m-file Function is a black box that communicates with workspace through input and output variables. INPUT FUNCTION Commands Functions Intermediate variables OUTPUT

134 From function to m-file Every function must begin with a header: function output=function_name(inputs) Output variable Must match the file name input variable

135 There are script m-files and function m-files Function m-files allow you to change, for example a parameter, and the function m file then executes the program by using this specific value of the parameter Every time you change this parameter you can generate a new set of results Function files thus are much more flexible and are used if you want to do the same computations over and over again, but with changing input conditions

136 Writing User Defined Functions Functions are m-files which can be executed by specifying some inputs and supply some desired outputs. The code telling the Matlab that an m-file is actually a function is function out1=functionname(in1) function out1=functionname(in1,in2,in3) function [out1,out2]=functionname(in1,in2) You should write this command at the beginning of the m-file and you should save the m-file with a file name same as the function name

137 Syntax for m files The name of the function file MUST be the same as the function name, for example: Function file logarithm.m Inside this function m file you must write function result=logarithm(x) result = log(x)

138 Writing User Defined Functions: Examples Write a function : out=squarer (A, ind) Which takes the square of the input matrix if the input indicator is equal to 1 And takes the element by element square of the input matrix if the input indicator is equal to 2 Same Name

139 Writing User Defined Functions Another function which takes an input array and returns the sum and product of its elements as outputs The function sumprod(.) can be called from command window or an m-file as

140 At Matlab prompt type in edit to invoke M-file editor Save this file as test1.m

141 Use of M-File Click to create a new M-File Extension.m A text file containing script or function or program to run

142 Use of M-File Save file as Denem430.m If you include ; at the end of each statement, result will not be shown immediately

143 To run the M-file, type in the name of the file at the prompt, e.g. >> Denem430.m It will be executed provided that the saved file is in the known path Type in matlabpath to check the list of directories listed in the path Use path editor to add the path: File Set path

144 M-files : script and function files (script) To run the M-file, type in the name of the file at the prompt e.g. >>> test1 It will be executed provided that the saved file is in the known path Type in matlabpath to check the list of directories listed in the path Use path editor to add the path: File Set path

145 M-files : script and function files (function) Function a simple example function y=react_c(c,f) %react_c calculates the reactance of a capacitor. %The inputs are: capacitor value and frequency in hz %The output is 1/(wC) and angular frequency in rad/s y(1)=2*pi*f; w=y(1); y(2)=1/(w*c); File must be saved to a known path with filename the same as the function name and with an extension.m Call function by its name and arguments help react_c will display comments after the header

146 M-files : script and function files (function) Function a more realistic example function x=impedance(r,c,l,w) %IMPEDANCE calculates Xc,Xl and Z(magnitude) and %Z(angle) of the RLC connected in series %IMPEDANCE(R,C,L,W) returns Xc, Xl and Z (mag) and %Z(angle) at W rad/s %Used as an example for IEEE student, UTM %introductory course on MATLAB if nargin <4 error('not enough input arguments') end; x(1) = 1/(w*c); x(2) = w*l; Zt = r + (x(2) - x(1))*i; x(3) = abs(zt); x(4)= angle(zt); impedance.m

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga 203484 selected topic in transportation 2552/2 Introduction ti to MATLAB 1 Prepared by Lect.Weerakaset Suanpaga Outline Introduction and where to get MATLAB Data structure: matrices, vectors and operations

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab 1 Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

More information

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help Outline User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help User-based knn Algorithm Three main steps Weight all users with respect to similarity with the active user.

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

More information

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic

More information

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation CDA5530: Performance Models of Computers and Networks Chapter 8: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003 Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)

More information

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab? Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. Matlab is available for PC's, Macintosh and UNIX systems.

More information

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

Introduction to MATLAB Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

An Introduction to MATLAB II

An Introduction to MATLAB II Lab of COMP 319 An Introduction to MATLAB II Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 2: 16th Sep, 2013 1 Outline of Lab 2 Review of Lab 1 Matrix in Matlab

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

More information

A Quick Tutorial on MATLAB. Zeeshan Ali

A Quick Tutorial on MATLAB. Zeeshan Ali A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

More information

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

Eng Marine Production Management. Introduction to Matlab

Eng Marine Production Management. Introduction to Matlab Eng. 4061 Marine Production Management Introduction to Matlab What is Matlab? Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. Matlab is available

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Appendix A Glossary of Matlab Commands Mathematical Operations + Addition. Type help plus

More information

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Chapter 2. MATLAB Fundamentals

Chapter 2. MATLAB Fundamentals Chapter 2. MATLAB Fundamentals Choi Hae Jin Chapter Objectives q Learning how real and complex numbers are assigned to variables. q Learning how vectors and matrices are assigned values using simple assignment,

More information

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below. What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB

More information

Introduction To MATLAB Introduction to Programming GENG 200

Introduction To MATLAB Introduction to Programming GENG 200 Introduction To MATLAB Introduction to Programming GENG 200, Prepared by Ali Abu Odeh 1 Table of Contents M Files 2 4 2 Execution Control 3 Vectors User Defined Functions Expected Chapter Duration: 6 classes.

More information

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University MATLAB Fundamentals Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 2 &

More information

MATLAB Guide to Fibonacci Numbers

MATLAB Guide to Fibonacci Numbers MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations What is MATLAB? It stands for MATrix LABoratory It is developed by The Mathworks, Inc (http://www.mathworks.com) It is an interactive, integrated, environment for numerical computations for symbolic computations

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

CS129: Introduction to Matlab (Code)

CS129: Introduction to Matlab (Code) CS129: Introduction to Matlab (Code) intro.m Introduction to Matlab (adapted from http://www.stanford.edu/class/cs223b/matlabintro.html) Stefan Roth , 09/08/2003 Stolen

More information

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB? Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

More information

Matlab Tutorial 1: Working with variables, arrays, and plotting

Matlab Tutorial 1: Working with variables, arrays, and plotting Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.

More information

Learning from Data Introduction to Matlab

Learning from Data Introduction to Matlab Learning from Data Introduction to Matlab Amos Storkey, David Barber and Chris Williams a.storkey@ed.ac.uk Course page : http://www.anc.ed.ac.uk/ amos/lfd/ This is a modified version of a text written

More information

MatLab Just a beginning

MatLab Just a beginning MatLab Just a beginning P.Kanungo Dept. of E & TC, C.V. Raman College of Engineering, Bhubaneswar Introduction MATLAB is a high-performance language for technical computing. MATLAB is an acronym for MATrix

More information

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals ELEN E384: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals 1 Introduction In the last lab you learn the basics of MATLAB, and had a brief introduction on how vectors

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB In this laboratory session we will learn how to 1. Create matrices and vectors. 2. Manipulate matrices and create matrices of special types

More information

MATLAB Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

CSE/Math 485 Matlab Tutorial and Demo

CSE/Math 485 Matlab Tutorial and Demo CSE/Math 485 Matlab Tutorial and Demo Some Tutorial Information on MATLAB Matrices are the main data element. They can be introduced in the following four ways. 1. As an explicit list of elements. 2. Generated

More information

6.094 Introduction to MATLAB January (IAP) 2009

6.094 Introduction to MATLAB January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.094 Introduction to MATLAB January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.094 Introduction

More information

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory provides a brief

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

General MATLAB Information 1

General MATLAB Information 1 Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting

More information

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB 1 INTRODUCTION TO MATLAB PLOTTING WITH MATLAB Plotting with MATLAB x-y plot Plotting with MATLAB MATLAB contains many powerful functions for easily creating plots of several different types. Command plot(x,y)

More information

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

More information

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo MATLAB is very powerful and varied software package for scientific computing. It is based upon matrices and m files. It is invoked by typing % matlab

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB (MATrix LABoratory) Presented By: Dr Mostafa Elshahed Asst. Prof. 1 Upon completing this course, the student should be able to: Learn a brief introduction to programming in MATLAB.

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Table of Contents. Basis CEMTool 7 Tutorial

Table of Contents. Basis CEMTool 7 Tutorial PREFACE CEMTool (Computer-aided Engineering & Mathematics Tool) is a useful computational tool in science and engineering. No matter what you background be it physics, chemistry, math, or engineering it

More information

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

QUICK INTRODUCTION TO MATLAB PART I

QUICK INTRODUCTION TO MATLAB PART I QUICK INTRODUCTION TO MATLAB PART I Department of Mathematics University of Colorado at Colorado Springs General Remarks This worksheet is designed for use with MATLAB version 6.5 or later. Once you have

More information

Laboratory 1 Octave Tutorial

Laboratory 1 Octave Tutorial Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory

More information

AMS 27L LAB #1 Winter 2009

AMS 27L LAB #1 Winter 2009 AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine

More information

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

MATLAB Functions and Graphics

MATLAB Functions and Graphics Functions and Graphics We continue our brief overview of by looking at some other areas: Functions: built-in and user defined Using M-files to store and execute statements and functions A brief overview

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Chapter 1 MATLAB Preliminaries

Chapter 1 MATLAB Preliminaries Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering

More information

A Very Brief Introduction to Matlab

A Very Brief Introduction to Matlab A Very Brief Introduction to Matlab by John MacLaren Walsh, Ph.D. for ECES 63 Fall 26 October 3, 26 Introduction To MATLAB You can type normal mathematical operations into MATLAB as you would in an electronic

More information

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download)

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download) Course Layout Lectures 1: Variables, Scripts and Operations 2: Visualization and Programming 3: Solving Equations, Fitting 4: Images, Animations, Advanced Methods 5: Optional: Symbolic Math, Simulink Course

More information

Fundamentals of MATLAB Usage

Fundamentals of MATLAB Usage 수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math

More information