A Mini course on MATLAB

Size: px
Start display at page:

Download "A Mini course on MATLAB"

Transcription

1 A Mini course on MATLAB MATLAB Basics, Matrix Algebra and Scripting Arun K. Tangirala 1 1 Department of Chemical Engineering Indian Institute of Technology Madras Mini Course on MATLAB A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

2 About MATLAB About MATLAB MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. - from Mathworks MATLAB is available on all three major operating systems SIMULINK, a powerful simulator for modelling and simulating dynamic systems, usually accompanies MATLAB (requires separate orde) One of the biggest advantages of using MATLAB is one does not need to declare ahead of time, the type of variable being used The base version of MATLAB/SIMULINK is aptly supported by a variety of toolboxes A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

3 Outline 1 Matrices 2 Matrix manipulations 3 Graphics 4 General purpose commands 5 Programming basics 6 Scripts and Functions A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

4 Matrices Matrices and Arrays 1 % C r e a t e a column v e c t o r 2 xvec = [ 1 ; 2 ; 4 ; 5 ] ; % OR 3 xvec = [ ] ; % N o t i c e the t r a n s p o s e 4 5 % One c o u l d a l s o c r e a t e a u n i f o r m l y spaced v e c t o r 6 uvec = ( 0 : : ) ; % This v e c t o r has 1000 samples 7 8 % Now how to c r e a t e a m a t r i x 9 A = [ 1 2 ; 4 5 ] ; 10 % OR a s s i g n each element 11 A( 1, 1 ) = 1 ; A( 2, 1 ) = 2 ; A( 1, 2 ) = 4 ; A( 2, 2 ) = 5 ; 12 % OR 13 A= zeros ( 3, 3 ) ; 14 A( 1 ) = 1 ; A( 2 ) = 2 ; A( 3 ) = 4 ; A( 4 ) = 5 ; 15 % N o t i c e above how the m a t r i x is d e f i n e d l i k e an array Removing the semicolon at the end allows you to echo the output A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

5 Matrices Creating matrices/arrays Both matrices and vectors are enclosed in square brackets Elements are accessed using the parentheses One can always append and/or insert elements to these objects A wide variety of manipulations are possible. A vector is a special case of a matrix 1 % Access the f i r s t two and l a s t two e l e m e n t s of uvec 2 uvec ( [ 1 2 end 1 end ]) 3 % Take e v e r y t h i r d element of uvec and s t o r e it in yvec 4 yvec = uvec ( 1 : 3 : end ); 5 % Size of a m a t r i x / v e c t o r & the t o t a l number of e l e m e n t s 6 [ nrow, n c o l ] = s i z e (A ) ; n e l A = numel (A ) ; 7 % Convert any m a t r i x or a v e c t o r i n t o a column v e c t o r 8 Acol = A ( : ) ; A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

6 Matrices Special matrices/vectors MATLAB allows one to create a variety of special matrices that appear in several problems One can even produce a large matrix containing replicates of a smaller matrix 1 % C r e a t e an i d e n t i t y m a t r i x 2 Imat = eye ( 3, 3 ) ; % Try eye ( 3, 2 ) 3 % C r e a t e a m a t r i x of ones or z e r o s 4 Amat = ones ( 3, 3 ) ; % OR 5 Amat = ones ( s i z e ( Imat ) ) ; 6 % S p e c i a l m a t r i c e s 7 hadamard ( 2 ) % Hadamard m a t r i x 8 magic ( 3 ) % Magic m a t r i x 9 t o e p l i t z ( [ 3 4 ], [ 3 2 ] ) % T o e p l i t z m a t r i x 10 % R e p l i c a t e a s m a l l m a t r i x 11 A=randn ( 2, 2 ) ; B = repmat (A, 2, 3 ) ; A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

7 Matrices Simple checks on matrices/arrays In some situations, it becomes necessary to make some important checks on the matrices of interest 1 % Check if a m a t r i x is empty 2 A = [ ] ; isempty (A) 3 % Check if two m a t r i c e s are e q u a l 4 A=exp ( [ 1 2 ; 3 4 ] ) ; B = expm ( [ 1 2 ; 3 4 ] ) ; 5 i s e q u a l (A, B) 6 % Check if a m a t r i x c o n t a i n s numeric e l e m e n t s 7 A = [ red ; blue ]; % N o t i c e the t r a i l i n g space a f t e r 8 i s n u m e r i c (A) 9 % Check if a m a t r i x c o n t a i n s r e a l e l e m e n t s 10 A = ones ( 2, 2 ) ; B = zeros ( 2, 2 ) ; C = A + j B; 11 i s r e a l (C) 12 i s r e a l ( complex (A) ) 13 % Check if m a t r i x e l e m e n t s are NaN 14 A = [ 1 2 ; i n f 4 ] ; 15 isnan (A) A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

8 Simple matrix operations Matrices Several operations can be carried out using simple commands 1 % Transpose a m a t r i x 2 A = [ ; ] ; A 3 A = [ i ; i ] ; A 4 % F l i p a m a t r i x 5 A = [ ; ] ; f l i p u d (A) 6 f l i p l r (A) 7 % E x t r a c t t r i a n g u l a r part 8 t r i l (A) 9 % Find i n d i c e s of z e r o e l e m e n t s 10 f i n d (A) 11 f i n d (A >= 4) 12 % C r e a t e a 3D m a t r i x s t a r t i n g from a 2D m a t r i x 13 A = [ 1 2 ; 3 4 ] ; A ( :, :, 2 ) = [ 5 6 ; 7 8 ] 14 % Remove s i n g l e t o n d i mension 15 s q u e e z e ( rand ( 3, 2, 1 ) ) A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

9 Matrix manipulations Mathematical operations on matrices We now learn how to perform some important mathematical operations 1 % Matrix m u l t i p l i c a t i o n s 2 A = [ ; ] ; B = randn ( 2, 2 ) ; A B % R e g u l a r product 3 A = [ 1 2 ; 3 4 ] ; B = [ 5 6 ; 7 8 ] ; A. B % Element w i s e m u l 4 % F i n d the maximum and minimum 5 A = [ ; 2 1]; max(a) 6 min( abs(a) ) 7 % Find the i n v e r s e and d e t e r m i n a n t of a m a t r i x 8 A = [ 1 2 ; 4 6 ] ; inv (A) 9 A = [ ; ] ; det(a A) 10 pinv (A) % Pseudo i n v e r s e of A 11 % Norm and t r a c e of a m a t r i x 12 A = [ 1 2 ; 3 4 ] ; norm(a) 13 norm(a, i n f ) 14 trace (A) % Trace of a m a t r i x 15 sum( diag(a) ) % This s h o u l d e q u a l t r a c e A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

10 Matrix manipulations Mathematical operations on matrices 1 % Matrix d i v i s i o n ( r e g u l a r and element w i s e ) 2 A = [ 1 2 ; 3 4 ] ; B = [ 5 6 ; 7 8 ] ; B/A 3 B inv (A) 4 B. /A 5 % E i g e n v a l u e c a l c u l a t i o n s 6 A = [ 1 2 ; 3 4 ] ; [VA, lama ] = eig (A) 7 inv (VA) expm( lama ) VA 8 expm(a) 9 % Rank of a m a t r i x 10 rank ( [ 4 5 ; ] ) 11 % C h a r a c t e r i s t i c e q u a t i o n 12 cpa = poly ( [ 1 2 ; 3 4 ] ) ; 13 roots( cpa ) % Compare with e i g e n v a l u e s of A 14 % LU f a c t o r i z a t i o n 15 [ L,U] = lu ( [ 1 2 ; 3 4 ] ) 16 % O r t h o g o n a l i z a t i o n 17 Q= orth ( [ 1 2 ; 3 4 ] ) continued A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

11 Matrix manipulations Special numbers and variables pi : The number π eps : Floating point relative accuracy inf : The number (too large a number) i : The imaginary number i = 1 (could use j) NaN : Not-a-Number (e.g., addition or subtraction of Inf) ans : The most recent answer end : The last element of a vector; OR to indicate the end of a loop or a conditional statement all : A function that returns 1 if none of the elements of a vector are zero; used with clear command to clear all variables A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

12 Elementary functions Matrix manipulations Trigonometric: sin, sinh, atan, sec, etc. Exponential: exp, log2, pow2, nextpow2, sqrt, etc. Complex: abs, angle, conj, imag, unwrap, etc. Rounding: fix, floor, ceil, mod, rem, sign, etc. Specialized: bessel, beta, erf, dot, gamma, etc. Number theoretic: factor, primes, factorial, gcd, nchoosek, etc. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

13 Matrix manipulations Examples 1 % C r e a t e 1000 samples of a s i n e and c o s i n e 2 x = cos (2 pi 0. 2 ( 0 : ) ) ; y = s i n (2 pi 0. 2 ( 0 : ) ) ; 3 f i n d ( ( x. ˆ 2 + y. ˆ 2 ) = 1) % Sum s q u a r e s s h o u l d e q u a l 1 4 % C r e a t e a complex number 5 z = x + i y; i s r e a l ( z + conj ( z ) ) 6 a r g z = unwrap ( angle ( z ) ) ; 7 % Rounding 8 v = [ ]; round ( v ) 9 c e i l ( v ) 10 sign ( v ) 11 % Generate p r i mes 12 p r i m e s ( 10) 13 % Find dot p r oduct 14 v1 = ( 1 : 4 ) ; v2 = s q r t ( v1 ) ; 15 dot( v1, v2 ) 16 sum( v1. v2 ) A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

14 Graphics Graphics We now turn to learning how to plot data and modify the resulting plots 1 % C r e a t e the time v e c t o r and s i n e v e c t o r 2 t v e c = ( 0 : : 9 9 ) ; 3 x t = s i n (2 pi 0.2 t v e c ) ; 4 % P l o t the first 20 samples of s i n e 5 p l o t ( t v e c ( 1 : 2 0 ), x t ( 1 : 2 0 ) ) ; 6 % Give a t i t l e and l a b e l s, and t u r n the g r i d on 7 t i t l e ( Plot of f i r s t 20 samples of s i n u s o i d ); 8 x l a b e l ( Samples ); y l a b e l ( Amplitude ); 9 g r i d on 10 % Also p l o t a c o s i n e of the same f r e q u e n c y with a r ed lin 11 y t = cos (2 pi 0.2 t v e c ) ; 12 hold on % Hold the c u r r e n t f i g u r e 13 p l o t ( t v e c ( 1 : 2 0 ), y t ( 1 : 2 0 ), r ); A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

15 Graphics Subplots One can draw different figures in different plots but on the same figure! 1 t v e c = l i n s p a c e ( , 4, ) ; % C r e a t e a l i n e a r l y spaced t 2 % C r e a t e a new f i g u r e 3 f i g u r e 4 % P l o t the first c u r v e at the bottom 5 subplot ( ) ; % D i v i d e s the f i g u r e i n t o 2 rows and 1 colu 6 p l o t ( tvec, log10 ( t v e c ) ) ; 7 t i t l e ( Parabola ); x l a b e l ( Time ); y l a b e l ( Amplitude ); 8 g r i d on 9 % P l o t the second c u r v e at the top 10 subplot ( ) ; 11 semilogx ( tvec, log10 ( t v e c ) ) ; % Plot with l o g 1 0 ( t ) on x a x i 12 t i t l e ( Parabola ); x l a b e l ( Time ); y l a b e l ( Amplitude ); 13 g r i d on The general subplot(m,n,p) refers to the p th plot in the m n subplots A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

16 Graphics Modifying plots Each figure has a handle which provides access to all of its properties. 1 % C r e a t e x and y v e c t o r s 2 t = 2 pi ( 0 : ) ; x = s i n ( t ) ; y = cos ( t ) ; 3 % P l o t y vs. x 4 h f i g = f i g u r e ; % F i g u r e command r e t u r n s a h a n d l e 5 p l o t ( x, y,, l i n e w i d t h, 2 ) ; % S o l i d and thick l i n e 6 % Modify p l o t 7 g r i d on ; a x i s s q u a r e % Use s q u a r e axis to see the c i r c l e 8 set (h f i g, Color, [ ], Name, Famous I d e n t i t y ); 9 h ax = gca ; % Get h a n d l e to c u r r e n t axis 10 set (h ax, f o n t s i z e,12, fontweight, bold ); 11 % Set l a b e l s and t i t l e with d e s i r e d f o n t 12 x l a b e l ( x : s i n (\ theta ), f o n t s i z e,14) ; 13 y l a b e l ( y : cos (\ theta ), f o n t s i z e,14) ; 14 t i t l e ( s i n ˆ2(\ theta ) + cos ˆ2(\ theta ) = 1 ); 15 set ( get ( gca, T i t l e ), fontweight, bold ); A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

17 Graphics Some tips on graphics The get and set commands are used to retrieve the current properties and set the desired properties of that object The figure is the parent object, the axis its child and then the curves are the children of the axes There are a variety of plots possible - plot3d, contour, mesh, surf, image, etc. One can use LaTeX commands (see texlabel) to insert Greek symbols One can further change the tick labels and the tick numbers as desired. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

18 Graphics Saving and printing Every object in the figure can be assigned a tag. A specific object in the figure can be easily accessed by using the findobj command. All figures can be edited directly by means of the GUI under Edit Figure Properties (or type plotedit). Figures can be saved as a MATLAB figure that can be loaded at any later time Every figure can exported to a variety of format including EPS, PDF and JPG formats. Use commands clf to clear and close the current figure. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

19 General purpose commands General purpose commands General: help, demo, ver, doc Debugging: who, keyboard, disp, sprintf, return, error, debug Workspace: whos, save, load, clear, diary, format Editing: edit, open, pcode, which, pwd Miscellaneous: path, pathtool, cd, copyfile, mkdir, computer, clc Reading up the documentation and help on any function beforehand is very useful. MATLAB comes with a built-in editor which is very powerful. There is also an editor which allows you to edit variables directly. Use the clear command with caution The keyboard and return commands are two extremely useful commands for debugging. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

20 Examples General purpose commands 1 % Open diary to r e c o r d commands and output 2 d i a r y r e c o r d. t x t 3 % C r e a t e v a r i a b l e s in the workspace 4 A=randn ( 2, 2 ) ; B = { red ; log10 ( 2 ) ; rand ( 2, 1 ) } ; 5 C = s t r u c t ( Name, Rama, Age,24, Place, I n d i a ); 6 % Check if v a r i a b l e s have been c r e a t e d and t h e i r s i z e 7 whos 8 % D i s p l a y the s t r u c t u r e v a r i a b l e 9 disp (C) 10 % Save them i n t o a f i l e 11 save t r i a l. mat A B C 12 % Clear t h e s e v a r i a b l e s and then l o a d them 13 c l e a r a l l ; 14 load t r i a l. mat 15 % E d i t m a t r i x A 16 open A 17 d i a r y o f f % Switch o f f the d i a r y A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

21 Programming basics Controlled flow 1 xvec = ( 1 0 : : 1 0 ) ; y f = [ ] ; 2 % Begin the f o r l o o p 3 f o r k = 1 : length ( xvec ), 4 if ( x ( k ) < 0 ), 5 y f ( k ) = 2 x ( k )ˆ2 + 3 ; 6 e l s e 7 y f ( k ) = x ( k ) + 3 ; 8 end 9 end 10 % Try u s i n g w h i l e l o o p 11 count = 1 ; yw = [ ] ; 12 while ( count <= length ( xvec ) ) 13 if ( x ( count ) < 0 ), 14 yw = [ y 2 x ( count )ˆ2+3]; 15 e l s e 16 yw = [ y x +3]; 17 end 18 count = count + 1 ; 19 end 20 % Check if both r e s u l t s a r e e q u a l 21 i s e q u a l ( yf, yw ) ; A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

22 Programming basics Controlled flow using switch Here, we do the same task using switch command. 1 x = ( 1 0 : : 1 0 ) ; ys = [ ] ; 2 f o r k = 1 : length ( x ) 3 s w i t c h ( x ( k ) < 0) 4 c a s e 1 5 ys ( k ) = 2 x ( k )ˆ2 + 3 ; 6 o t h e r w i s e 7 ys ( k ) = x ( k ) + 3 ; 8 end 9 end 10 % Try u s i n g a d i f f e r e n t method 11 % Use the f i n d f u n c t i o n 12 indneg = f i n d (x < 0 ) ; indnonneg = f i n d (x >= 0 ) ; 13 yn = [ ] ; 14 yn ( i n dneg ) = 2 x ( indneg ). ˆ ; 15 yn ( indnonneg ) = x ( indnonneg ) + 3 ; 16 % Check if both are e q u a l 17 i s e q u a l ( ys ( : ), yn ( : ) ) A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

23 Programming basics Useful language commands Controlled flow: break, continue, try, catch Evaluation: eval, feval, run, assignin, Scripting: function, global, mfilename, nargin, varargin, nargchk Messaging: warning, display, fprintf, Interactive: input, pause, uimenu A function in MATLAB is similar to a subroutine in C. A function takes in input arguments, processes them and produces output arguments. The variables used within the function have a limited scope. They exist as long as only the function is being executed. Global variables are useful to access variables in the function workspace from the regular workspace and, therefore, should be used with caution. Commands such as input and uimenu could be used for interactively seeking inputs from the user. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

24 Polynomial functons Programming basics Polynomials: poly, roots, polyval, polyfit, polyder, conv Interpolation: interpft, interp1, spline, interp1q 1 % C r e a t e a p o l y n o m i a l 2 px = poly ( [ 1 2 ] ) % Takes in the r o o t s of the p o l y n o m i a l 3 % E v a l u a t e the p o l y n o m i a l at x = 1, 2, 3 4 p o l y v a l ( px, [ ] ) 5 % Find r o o t s of a p o l y n o m i a l : x ˆ3 + 6x ˆ2 + 11x x r = roots ( [ ] ) % Takes in the c o e f f i c i e n t s 7 px = poly ( x r ) ; % Check if you get back the same answer 8 % Convolve p o l y n o m i a l s ( x+1) and ( x ˆ2 + 5x + 6) 9 gx = conv ( [ 1 1 ], [ ] ) % P r o v i d e the c o e f f i c i e n t s 10 % F i t t i n g p o l y n o m i a l to data 11 xk = ( 0 : : 9 9 ) ; 12 yk = xk. ˆ xk randn( length ( xk ), 1 ) ; 13 [c e s t, s e s t ] = p o l y f i t ( xk, yk, 2 ) A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

25 Scripts and Functions Script file A script file in MATLAB is any set of MATLAB commands which are executed in that sequence. Script files have a.m extension. Use a meaningful name for the filename A script file can be run by simply typing the filename without its extension. The scope of the variables used in a script file is the general workspace. They can be accessed even after the execution. A script file can contain functions which can be used within that script. MATLAB executes the script file by interpreting every line, which makes it somewhat slow at times. An m-file script can be converted into a psuedo code using the pcode command. The resulting file runs faster than the m-file. A script file can be put on path so that it can be called from any directory. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

26 Script file: Example Scripts and Functions 1 % SCRIPT FILE TO SOLVE A SET OF LINEAR EQUATIONS 2 % S o l v e A p = b f o r p 3 A=magic ( 3 ) ; b = ( 1 : 3 ) ; 4 p = inv (A) b 5 % A l t e r n a t i v e l y 6 p2 = A \ b 7 % L i n e a r e q u a t i o n s a r i s e in system i d e n t i f i c a t i o n f o r example 8 % Generate input output data mixed with n o i s e 9 Phi = randn ( , 3 ) ; 10 Y = Phi p randn ( , 1 ) ; 11 % E s t i m a t e the p a r a m e t e r s u s i n g LS method 12 p l s = Phi \ Y % OR 13 p l s = pinv ( Phi ) Y 14 % Use l e a s t s q u a r e s f u n c t i o n from o p t i m i z a t i o n 15 p l s = l s q l i n ( Phi, Y ) ; 16 % Compare the p r e d i c t e d vs. a c t u a l output 17 Yhat = Phi p l s ; 18 f i g u r e 19 p l ot (Y, Yhat, x,y, Y, r ); 20 g r i d on ; a x i s t i g h t ; t i t l e ( Predicted vs. Actual ); 21 x l a b e l ( Y ); y l a b e l ( Yhat ); legend ({ Predicted ; I d e a l } ); A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

27 Scripts and Functions Function files Every function file should begin as: function yout = myfun(xin) where yout and xin are generic output and input arguments of that function In principle, a function can be written without the output argument or input arguments Any comments immediately below the function declaration line and until the next blank or declaration line will be used by the help command to give help on that function. The input and output variable names are dummy names. The variables only exist as long as the function is being executed. A function is available for execution as soon as it is saved. Functions can be accessed by handles, which are passed on to several other functions such as ode45, feval, etc. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

28 Scripts and Functions Function file: Simple Example 1 function r s o l = q u a d s o l ( cvec ) ; 2 % F u n c t i o n to compute the r o o t s of a q u a d r a t i c e q u a t i o n 3 % 4 % Usage : r s o l = quad sol( cvec ); 5 6 % Read the c o e f f i c i e n t s 7 a = cvec ( 1 ) ; b = cvec ( 2 ) ; c = cvec ( 3 ) ; 8 9 % Compute the s o l u t i o n 10 r s o l = [ ] ; 11 r s o l ( 1 ) = ( b + s q r t ( bˆ2 4 a c ) ) / ( 2 a ) ; 12 r s o l ( 2 ) = ( b s q r t ( bˆ2 4 a c ) ) / ( 2 a ) ; Ideally one should also describe the input and output arguments The output could be of any type and any in number Variable number of input arguments could be supplied A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

29 Scripts and Functions Function file: Advanced Example 1 function pspec = p s p e c f u n ( x, p l o t o p t ) 2 % F u n c t i o n to compute and p l o t the power spectrum 3 % of a s i g n a l u s i n g s t a n d a r d and smoothed t e c h n i q u e s 4 % Usage : pspec = p s p e c f u n ( x, p l o t o p t ); 5 6 % Set o p t i o n a l argument if not s u p p l i e d 7 if ( nargin == 1 ), p l o t o p t = 1 ; end 8 % Read the time s e r i e s i n f o r m a t i o n 9 x = x ( : ) ; nsamp = length ( x ) ; 10 % Compute the raw power spectrum 11 x f = fft( x ) ; xps raw = abs( x f ( 1 : end / 2 ) ). ˆ 2 ; 12 f = ( 0 : 1 / nsamp :0.5 1/ nsamp ) ; 13 % Compute the smoothed power spectrum 14 [ xps welch, F ] = pwelch ( x, ) ; 15 % Return the output in pspec 16 pspec = s t r u c t ( Xpsraw, [ f xps raw ], Xpswelch [ F x p s w e l c h ] ) ; 17 % P l o t if opted 18 if ( p l o t o p t == 1) 19 f i g u r e 20 subplot ( ) ; 21 p l o t ( f, xps raw ) ; g r i d on ; a x i s t i g h t 22 subplot (212) 23 p l o t (F/(2 max(f ) ), x p s w e l c h ) ; g r i d on ; a x i s t i g h t 24 end A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

30 Scripts and Functions Function related functions Optimization: fzero, fsolve, fminbnd, lsqnonlin, lsqcurvefit, linprog, etc. Calculus: quad, ode45, pdepe, dde23, etc. Plotting: fplot, odeplot, ezplot, ezmesh, etc. Miscellaneous: inline, eval, argnames, formula, etc. Most of the functions require handles of functions to be passed to them. The functions related to numerical integration require the functions to return derivatives. A.K. Tangirala (IIT Madras) Introduction to MATLAB/SIMULINK October / 30

3. Array and Matrix Operations

3. Array and Matrix Operations 3. Array and Matrix Operations Almost anything you learned about in your linear algebra classmatlab has a command to do. Here is a brief summary of the most useful ones for physics. In MATLAB matrices

More information

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB, Part I: Basics MATLAB Environment Getting Help Variables Vectors, Matrices, and

More information

Using MATLAB. Linear Algebra

Using MATLAB. Linear Algebra Using MATLAB in Linear Algebra Edward Neuman Department of Mathematics Southern Illinois University at Carbondale One of the nice features of MATLAB is its ease of computations with vectors and matrices.

More information

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB (Mathematical Operations with Arrays) Contents Getting Started Matrices Creating Arrays Linear equations Mathematical Operations with Arrays Using Script

More information

Table 1 Principle Matlab operators and functions Name Description Page reference

Table 1 Principle Matlab operators and functions Name Description Page reference Matlab Index Table 1 summarises the Matlab supplied operators and functions to which we have referred. In most cases only a few of the options available to the individual functions have been fully utilised.

More information

USE OF MATLAB TO UNDERSTAND BASIC MATHEMATICS

USE OF MATLAB TO UNDERSTAND BASIC MATHEMATICS USE OF MATLAB TO UNDERSTAND BASIC MATHEMATICS Sanjay Gupta P. G. Department of Mathematics, Dev Samaj College For Women, Punjab ( India ) ABSTRACT In this paper, we talk about the ways in which computer

More information

Applied Linear Algebra in Geoscience Using MATLAB

Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional Plots Programming in

More information

2D Plotting with Matlab

2D Plotting with Matlab GEEN 1300 Introduction to Engineering Computing Class Meeting #22 Monday, Nov. 9 th Engineering Computing and Problem Solving with Matlab 2-D plotting with Matlab Script files User-defined functions Matlab

More information

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu MATLAB BASICS Instructor: Prof. Shahrouk Ahmadi 1. What are M-files TA: Kartik Bulusu M-files are files that contain a collection of MATLAB commands or are used to define new MATLAB functions. For the

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Macroeconomics Vivaldo Mendes Dep. Economics Instituto Universitário de Lisboa September 2017 (Vivaldo Mendes ISCTE-IUL ) Macroeconomics September 2013 1 / 41 Summary 1 Introduction

More information

WILEY. Differential Equations with MATLAB (Third Edition) Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg

WILEY. Differential Equations with MATLAB (Third Edition) Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg Differential Equations with MATLAB (Third Edition) Updated for MATLAB 2011b (7.13), Simulink 7.8, and Symbolic Math Toolbox 5.7 Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg All

More information

L3: Review of linear algebra and MATLAB

L3: Review of linear algebra and MATLAB L3: Review of linear algebra and MATLAB Vector and matrix notation Vectors Matrices Vector spaces Linear transformations Eigenvalues and eigenvectors MATLAB primer CSCE 666 Pattern Analysis Ricardo Gutierrez-Osuna

More information

Math 307 Learning Goals. March 23, 2010

Math 307 Learning Goals. March 23, 2010 Math 307 Learning Goals March 23, 2010 Course Description The course presents core concepts of linear algebra by focusing on applications in Science and Engineering. Examples of applications from recent

More information

TOPIC 2 Computer application for manipulating matrix using MATLAB

TOPIC 2 Computer application for manipulating matrix using MATLAB YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM TOPIC 2 Computer application for manipulating matrix using MATLAB Definition of Matrices in MATLAB

More information

Homework 1 Solutions

Homework 1 Solutions 18-9 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 18 Homework 1 Solutions Part One 1. (8 points) Consider the DT signal given by the algorithm: x[] = 1 x[1] = x[n] = x[n 1] x[n ] (a) Plot

More information

Spis treści Contents List of Examples Preface to Third Edition 21

Spis treści Contents List of Examples Preface to Third Edition 21 An engineer's guide to MATLAB : with applications from mechanical, aerospace, electrical, civil, and biological systems engineering / Edward B. Magrab [et al.]. - 3rd ed. - Boston, cop. 2011 Spis treści

More information

An Introduction to MatLab

An Introduction to MatLab Introduction to MatLab 1 An Introduction to MatLab Contents 1. Starting MatLab... 3 2. Workspace and m-files... 4 3. Help... 5 4. Vectors and Matrices... 5 5. Objects... 8 6. Plots... 10 7. Statistics...

More information

Who am I? Math 1080: Numerical Linear Algebra. Books. Format

Who am I? Math 1080: Numerical Linear Algebra. Books. Format Who am I? Math 18: Numerical Linear Algebra M M Sussman sussmanm@mathpittedu Office Hours: MW 1:45PM-2:45PM, Thack 622 Part-time faculty in Math Dept Experience at Bettis lab Administer 27/271 Numerical

More information

MATLAB for Chemical Engineering

MATLAB for Chemical Engineering MATLAB for Chemical Engineering Dr. M. Subramanian Associate Professor Department of Chemical Engineering Sri Sivasubramaniya Nadar College of Engineering OMR, Chennai 603110 msubbu.in[at]gmail.com 16

More information

Introduction to MatLab

Introduction to MatLab Introduction to MatLab 1 Introduction to MatLab Graduiertenkolleg Kognitive Neurobiologie Friday, 05 November 2004 Thuseday, 09 Novemer 2004 Kurt Bräuer Institut für Theoretische Physik, Universität Tübingen

More information

Note: The command name is upper case in the description given by help, but must be lower case in actual use. And the backslash Anb is dierent when A i

Note: The command name is upper case in the description given by help, but must be lower case in actual use. And the backslash Anb is dierent when A i MATLAB Tutorial You need a small number of basic commands to start using MATLAB. This short tutorial describes those fundamental commands. You need to create vectors and matrices, to change them, and to

More information

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB (Linear equations) Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional Plots

More information

Lab 2: Static Response, Cantilevered Beam

Lab 2: Static Response, Cantilevered Beam Contents 1 Lab 2: Static Response, Cantilevered Beam 3 1.1 Objectives.......................................... 3 1.2 Scalars, Vectors and Matrices (Allen Downey)...................... 3 1.2.1 Attribution.....................................

More information

ENGR Spring Exam 2

ENGR Spring Exam 2 ENGR 1300 Spring 013 Exam INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully..

More information

New Mexico Tech Hyd 510

New Mexico Tech Hyd 510 Vectors vector - has magnitude and direction (e.g. velocity, specific discharge, hydraulic gradient) scalar - has magnitude only (e.g. porosity, specific yield, storage coefficient) unit vector - a unit

More information

LAB 1: MATLAB - Introduction to Programming. Objective:

LAB 1: MATLAB - Introduction to Programming. Objective: LAB 1: MATLAB - Introduction to Programming Objective: The objective of this laboratory is to review how to use MATLAB as a programming tool and to review a classic analytical solution to a steady-state

More information

Model-building and parameter estimation

Model-building and parameter estimation Luleå University of Technology Johan Carlson Last revision: July 27, 2009 Measurement Technology and Uncertainty Analysis - E7021E MATLAB homework assignment Model-building and parameter estimation Introduction

More information

Companion. Jeffrey E. Jones

Companion. Jeffrey E. Jones MATLAB7 Companion 1O11OO1O1O1OOOO1O1OO1111O1O1OO 1O1O1OO1OO1O11OOO1O111O1O1O1O1 O11O1O1O11O1O1O1O1OO1O11O1O1O1 O1O1O1111O11O1O1OO1O1O1O1OOOOO O1111O1O1O1O1O1O1OO1OO1OO1OOO1 O1O11111O1O1O1O1O Jeffrey E.

More information

Lecture 4. Programming

Lecture 4. Programming Lecture 4 Advanced Matlab Programming Announcements Hands-on Session on Friday 1318 EB Read Chapters 3-6 in your MATLAB book HW 2 opens up Friday evening Today Numerical analysis - I Visualization I Some

More information

+ MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS

+ MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS + MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS Matrices are organized rows and columns of numbers that mathematical operations can be performed on. MATLAB is organized around the rules of matrix operations.

More information

CISE 302 Linear Control Systems Laboratory Manual

CISE 302 Linear Control Systems Laboratory Manual King Fahd University of Petroleum & Minerals CISE 302 Linear Control Systems Laboratory Manual Systems Engineering Department Revised - September 2012 2 Lab Experiment 1: Using MATLAB for Control Systems

More information

Octave. Tutorial. Daniel Lamprecht. March 26, Graz University of Technology. Slides based on previous work by Ingo Holzmann

Octave. Tutorial. Daniel Lamprecht. March 26, Graz University of Technology. Slides based on previous work by Ingo Holzmann Tutorial Graz University of Technology March 26, 2012 Slides based on previous work by Ingo Holzmann Introduction What is? GNU is a high-level interactive language for numerical computations mostly compatible

More information

A Glimpse at Scipy FOSSEE. June Abstract This document shows a glimpse of the features of Scipy that will be explored during this course.

A Glimpse at Scipy FOSSEE. June Abstract This document shows a glimpse of the features of Scipy that will be explored during this course. A Glimpse at Scipy FOSSEE June 010 Abstract This document shows a glimpse of the features of Scipy that will be explored during this course. 1 Introduction SciPy is open-source software for mathematics,

More information

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra A. Vectors A vector is a quantity that has both magnitude and direction, like velocity. The location of a vector is irrelevant;

More information

Linear System Theory

Linear System Theory Linear System Theory - Introduction to Simulink Prof. Robert X. Gao Electromechanical Systems Laboratory Department of Mechanical Engineering Outline Block Diagram Introduction Launching Simulink Modeling

More information

Physics with Matlab and Mathematica Exercise #1 28 Aug 2012

Physics with Matlab and Mathematica Exercise #1 28 Aug 2012 Physics with Matlab and Mathematica Exercise #1 28 Aug 2012 You can work this exercise in either matlab or mathematica. Your choice. A simple harmonic oscillator is constructed from a mass m and a spring

More information

CHAPTER 6 STATE SPACE: FREQUENCY RESPONSE, TIME DOMAIN

CHAPTER 6 STATE SPACE: FREQUENCY RESPONSE, TIME DOMAIN CHAPTER 6 STATE SPACE: FREQUENCY RESPONSE, TIME DOMAIN 6. Introduction Frequency Response This chapter will begin with the state space form of the equations of motion. We will use Laplace transforms to

More information

Lecture 5b: Starting Matlab

Lecture 5b: Starting Matlab Lecture 5b: Starting Matlab James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University August 7, 2013 Outline 1 Resources 2 Starting Matlab 3 Homework

More information

SIGNALS AND LINEAR SYSTEMS LABORATORY EELE Experiment (2) Introduction to MATLAB - Part (2) Prepared by:

SIGNALS AND LINEAR SYSTEMS LABORATORY EELE Experiment (2) Introduction to MATLAB - Part (2) Prepared by: The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department SIGNALS AND LINEAR SYSTEMS LABORATORY EELE 110 Experiment () Introduction to MATLAB - Part () Prepared by: Eng. Mohammed

More information

EE 4314 Lab 1 Handout Control Systems Simulation with MATLAB and SIMULINK Spring Lab Information

EE 4314 Lab 1 Handout Control Systems Simulation with MATLAB and SIMULINK Spring Lab Information EE 4314 Lab 1 Handout Control Systems Simulation with MATLAB and SIMULINK Spring 2013 1. Lab Information This is a take-home lab assignment. There is no experiment for this lab. You will study the tutorial

More information

Linear Algebra Using MATLAB

Linear Algebra Using MATLAB Linear Algebra Using MATLAB MATH 5331 1 May 12, 2010 1 Selected material from the text Linear Algebra and Differential Equations Using MATLAB by Martin Golubitsky and Michael Dellnitz Contents 1 Preliminaries

More information

EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL

EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL EE 213 Fall 2009 LABORATORY #1 INTRODUCTION TO MATLAB INTRODUCTION The purpose of this laboratory is to introduce you to Matlab and to illustrate some of its circuit

More information

1 Introduction & Objective

1 Introduction & Objective Signal Processing First Lab 13: Numerical Evaluation of Fourier Series Pre-Lab and Warm-Up: You should read at least the Pre-Lab and Warm-up sections of this lab assignment and go over all exercises in

More information

Introduction to GNU Octave

Introduction to GNU Octave Introduction to GNU Octave A brief tutorial for linear algebra and calculus students by Jason Lachniet Introduction to GNU Octave A brief tutorial for linear algebra and calculus students Jason Lachniet

More information

MODIFIED VERSION OF: An introduction to Matlab for dynamic modeling ***PART 2 *** Last compile: October 3, 2016

MODIFIED VERSION OF: An introduction to Matlab for dynamic modeling ***PART 2 *** Last compile: October 3, 2016 MODIFIED VERSION OF: An introduction to Matlab for dynamic modeling ***PART 2 *** Last compile: October 3, 2016 Stephen P. Ellner 1 and John Guckenheimer 2 1 Department of Ecology and Evolutionary Biology,

More information

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations Lab 2 Worksheet Problems Problem : Geometry and Linear Equations Linear algebra is, first and foremost, the study of systems of linear equations. You are going to encounter linear systems frequently in

More information

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP In this laboratory session we will learn how to. Use MATLAB solvers for solving scalar IVP 2. Use MATLAB solvers for solving higher order ODEs and

More information

INFE 5201 SIGNALS AND SYSTEMS

INFE 5201 SIGNALS AND SYSTEMS INFE 50 SIGNALS AND SYSTEMS Assignment : Introduction to MATLAB Name, Class&Student ID Aim. To give student an introduction to basic MATLAB concepts. You are required to produce basic program, learn basic

More information

Introduction to Computational Neuroscience

Introduction to Computational Neuroscience CSE2330 Introduction to Computational Neuroscience Basic computational tools and concepts Tutorial 1 Duration: two weeks 1.1 About this tutorial The objective of this tutorial is to introduce you to: the

More information

Introduction to GNU Octave

Introduction to GNU Octave Introduction to GNU Octave Second Edition A brief tutorial for linear algebra and calculus students by Jason Lachniet Introduction to GNU Octave A brief tutorial for linear algebra and calculus students

More information

Representing Polynomials

Representing Polynomials Lab 4 Representing Polynomials A polynomial of nth degree looks like: a n s n +a n 1 a n 1 +...+a 2 s 2 +a 1 s+a 0 The coefficients a n, a n-1,, a 2, a 1, a 0 are the coefficients of decreasing powers

More information

Lecture 5: Special Functions and Operations

Lecture 5: Special Functions and Operations Lecture 5: Special Functions and Operations Feedback of Assignment2 Rotation Transformation To rotate by angle θ counterclockwise, set your transformation matrix A as [ ] cos θ sin θ A =. sin θ cos θ We

More information

R: A Quick Reference

R: A Quick Reference R: A Quick Reference Colorado Reed January 17, 2012 Contents 1 Basics 2 1.1 Arrays and Matrices....................... 2 1.2 Lists................................ 3 1.3 Loading Packages.........................

More information

2 Getting Started with Numerical Computations in Python

2 Getting Started with Numerical Computations in Python 1 Documentation and Resources * Download: o Requirements: Python, IPython, Numpy, Scipy, Matplotlib o Windows: google "windows download (Python,IPython,Numpy,Scipy,Matplotlib" o Debian based: sudo apt-get

More information

Math 307 Learning Goals

Math 307 Learning Goals Math 307 Learning Goals May 14, 2018 Chapter 1 Linear Equations 1.1 Solving Linear Equations Write a system of linear equations using matrix notation. Use Gaussian elimination to bring a system of linear

More information

Physics 241 Class #10 Outline (9/25/2013) Plotting Handle graphics Numerical derivatives and functions Next time numerical integrals

Physics 241 Class #10 Outline (9/25/2013) Plotting Handle graphics Numerical derivatives and functions Next time numerical integrals Physics 241 Class #10 Outline (9/25/2013) Plotting Handle graphics Numerical derivatives and functions Next time numerical integrals Announcements HW4 grades are up. HW5a HW5 revised Same problems, now

More information

Lecture 4: Linear Algebra Review, Part III

Lecture 4: Linear Algebra Review, Part III Lecture 4: Linear Algebra Review, Part III Brian Borchers February 1, 000 1 Vector Norms Although the conventional Euclidean length is most commonly used, there are alternative ways to measure the length

More information

A Review of Linear Algebra

A Review of Linear Algebra A Review of Linear Algebra Gerald Recktenwald Portland State University Mechanical Engineering Department gerry@me.pdx.edu These slides are a supplement to the book Numerical Methods with Matlab: Implementations

More information

Adaptive Filtering. Squares. Alexander D. Poularikas. Fundamentals of. Least Mean. with MATLABR. University of Alabama, Huntsville, AL.

Adaptive Filtering. Squares. Alexander D. Poularikas. Fundamentals of. Least Mean. with MATLABR. University of Alabama, Huntsville, AL. Adaptive Filtering Fundamentals of Least Mean Squares with MATLABR Alexander D. Poularikas University of Alabama, Huntsville, AL CRC Press Taylor & Francis Croup Boca Raton London New York CRC Press is

More information

Lecture 7 Symbolic Computations

Lecture 7 Symbolic Computations Lecture 7 Symbolic Computations The focus of this course is on numerical computations, i.e. calculations, usually approximations, with floating point numbers. However, Matlab can also do symbolic computations,

More information

MAE 107 Homework 8 Solutions

MAE 107 Homework 8 Solutions MAE 107 Homework 8 Solutions 1. Newton s method to solve 3exp( x) = 2x starting at x 0 = 11. With chosen f(x), indicate x n, f(x n ), and f (x n ) at each step stopping at the first n such that f(x n )

More information

Computer Exercise 0 Simulation of ARMA-processes

Computer Exercise 0 Simulation of ARMA-processes Lund University Time Series Analysis Mathematical Statistics Fall 2018 Centre for Mathematical Sciences Computer Exercise 0 Simulation of ARMA-processes The purpose of this computer exercise is to illustrate

More information

MA3457/CS4033: Numerical Methods for Calculus and Differential Equations

MA3457/CS4033: Numerical Methods for Calculus and Differential Equations MA3457/CS4033: Numerical Methods for Calculus and Differential Equations Course Materials P A R T II B 14 2014-2015 1 2. APPROXIMATION CLASS 9 Approximation Key Idea Function approximation is closely related

More information

Numerical Methods Lecture 2 Simultaneous Equations

Numerical Methods Lecture 2 Simultaneous Equations CGN 42 - Computer Methods Numerical Methods Lecture 2 Simultaneous Equations Topics: matrix operations solving systems of equations Matrix operations: Adding / subtracting Transpose Multiplication Adding

More information

Laboratory 1. Solving differential equations with nonzero initial conditions

Laboratory 1. Solving differential equations with nonzero initial conditions Laboratory 1 Solving differential equations with nonzero initial conditions 1. Purpose of the exercise: - learning symbolic and numerical methods of differential equations solving with MATLAB - using Simulink

More information

Linear Algebra and Matrices

Linear Algebra and Matrices Linear Algebra and Matrices 4 Overview In this chapter we studying true matrix operations, not element operations as was done in earlier chapters. Working with MAT- LAB functions should now be fairly routine.

More information

Learning MATLAB by doing MATLAB

Learning MATLAB by doing MATLAB Learning MATLAB by doing MATLAB December 10, 2005 Just type in the following commands and watch the output. 1. Variables, Vectors, Matrices >a=7 a is interpreted as a scalar (or 1 1 matrix) >b=[1,2,3]

More information

ENGG1811 Computing for Engineers Week 11 Part B Matlab: Linear Indexing; Linear Equations, Curve Fitting, Short Circuit Evaluation

ENGG1811 Computing for Engineers Week 11 Part B Matlab: Linear Indexing; Linear Equations, Curve Fitting, Short Circuit Evaluation ENGG1811 Computing for Engineers Week 11 Part B Matlab: Linear Indexing; Linear Equations, Curve Fitting, Short Circuit Evaluation ENGG1811 UNSW, CRICOS Provider No: 00098G1 W11 slide 1 Linear indexing

More information

MATLAB for Engineers

MATLAB for Engineers MATLAB for Engineers Adrian Biran Moshe Breiner ADDISON-WESLEY PUBLISHING COMPANY Wokingham, England Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Amsterdam Bonn Sydney Singapore

More information

Typos/errors in Numerical Methods Using Matlab, 4th edition by Mathews and Fink

Typos/errors in Numerical Methods Using Matlab, 4th edition by Mathews and Fink MAT487 Fall 2004 David Hiebeler University of Maine http://www.math.umaine.edu/faculty/hiebeler Typos/errors in Numerical Methods Using Matlab, 4th edition by Mathews and Fink Please let me know if you

More information

Applied Linear Algebra in Geoscience Using MATLAB

Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional Plots Programming in

More information

(t) ), ( ) where t is time, T is the reaction time, u n is the position of the nth car, and the "sensitivity coefficient" λ may depend on un 1(

(t) ), ( ) where t is time, T is the reaction time, u n is the position of the nth car, and the sensitivity coefficient λ may depend on un 1( Page 1 A Model of Traffic Flow Everyone has had the experience of sitting in a traffic jam, or of seeing cars bunch up on a road for no apparent good reason MATLAB and SIMULINK are good tools for studying

More information

ECE2111 Signals and Systems UMD, Spring 2013 Experiment 1: Representation and manipulation of basic signals in MATLAB

ECE2111 Signals and Systems UMD, Spring 2013 Experiment 1: Representation and manipulation of basic signals in MATLAB ECE2111 Signals and Systems UMD, Spring 2013 Experiment 1: Representation and manipulation of basic signals in MATLAB MATLAB is a tool for doing numerical computations with matrices and vectors. It can

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Violeta Ivanova, Ph.D. Educational Technology Consultant MIT Academic Computing violeta@mit.edu http://web.mit.edu/violeta/www/iap2006 Topics MATLAB Interface and Basics Linear Algebra

More information

Chapter I: Hands-on experience in SCILAB operations

Chapter I: Hands-on experience in SCILAB operations Chapter I: Hands-on experience in SCILAB operations Introduction to SCILAB SCILAB is a numerical mathematical equation solver which involves a powerful open computing environment for engineering and scientific

More information

I. Numerical Computing

I. Numerical Computing I. Numerical Computing A. Lectures 1-3: Foundations of Numerical Computing Lecture 1 Intro to numerical computing Understand difference and pros/cons of analytical versus numerical solutions Lecture 2

More information

Math 56 Homework 1 Michael Downs. ne n 10 + ne n (1)

Math 56 Homework 1 Michael Downs. ne n 10 + ne n (1) . Problem (a) Yes. The following equation: ne n + ne n () holds for all n R but, since we re only concerned with the asymptotic behavior as n, let us only consider n >. Dividing both sides by n( + ne n

More information

Errata for First Printing of Numerical Methods with Matlab: Implementations and Applications

Errata for First Printing of Numerical Methods with Matlab: Implementations and Applications Errata for First Printing of Numerical Methods with Matlab: Implementations and Applications Gerald Recktenwald gerry@me.pdx.edu February 14, 2005 This document lists only the technical errors in the mathematics

More information

SECTION 2: VECTORS AND MATRICES. ENGR 112 Introduction to Engineering Computing

SECTION 2: VECTORS AND MATRICES. ENGR 112 Introduction to Engineering Computing SECTION 2: VECTORS AND MATRICES ENGR 112 Introduction to Engineering Computing 2 Vectors and Matrices The MAT in MATLAB 3 MATLAB The MATrix (not MAThematics) LABoratory MATLAB assumes all numeric variables

More information

EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL

EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL EE -213 BASIC CIRCUIT ANALYSIS LAB MANUAL EE 213 Spring 2008 LABORATORY #1 INTRODUCTION TO MATLAB INTRODUCTION The purpose of this laboratory is to introduce you to Matlab and to illustrate some of its

More information

Math Assignment 3 - Linear Algebra

Math Assignment 3 - Linear Algebra Math 216 - Assignment 3 - Linear Algebra Due: Tuesday, March 27. Nothing accepted after Thursday, March 29. This is worth 15 points. 10% points off for being late. You may work by yourself or in pairs.

More information

MATLAB crash course 1 / 27. MATLAB crash course. Cesar E. Tamayo Economics - Rutgers. September 27th, /27

MATLAB crash course 1 / 27. MATLAB crash course. Cesar E. Tamayo Economics - Rutgers. September 27th, /27 1/27 MATLAB crash course 1 / 27 MATLAB crash course Cesar E. Tamayo Economics - Rutgers September 27th, 2013 2/27 MATLAB crash course 2 / 27 Program Program I Interface: layout, menus, help, etc.. I Vectors

More information

Matlab Instruction Primer; Chem 691, Spring 2016

Matlab Instruction Primer; Chem 691, Spring 2016 1 Matlab Instruction Primer; Chem 691, Spring 2016 This version dated February 10, 2017 CONTENTS I. Help: To obtain information about any instruction in Matlab 1 II. Scripting 1 III. Loops, determine an

More information

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP MAT 75 Laboratory 4 MATLAB solvers for First-Order IVP In this laboratory session we will learn how to. Use MATLAB solvers for solving scalar IVP. Use MATLAB solvers for solving higher order ODEs and systems

More information

Matlab toolbox, User's Guide

Matlab toolbox, User's Guide Matlab toolbox, User's Guide François Cuvelier April 20, 2018 Abstract The more Matlab toolbox allows to benchmark functions and much Compiled with Matlab 2017a, with toolboxes fc-bench['dev'] and fc-tools['dev']

More information

Computational Foundations of Cognitive Science

Computational Foundations of Cognitive Science Computational Foundations of Cognitive Science Lecture 14: Inverses and Eigenvectors in Matlab; Plotting and Graphics Frank Keller School of Informatics University of Edinburgh keller@inf.ed.ac.uk February

More information

OKLAHOMA STATE UNIVERSITY

OKLAHOMA STATE UNIVERSITY OKLAHOMA STATE UNIVERSITY ECEN 4413 - Automatic Control Systems Matlab Lecture 1 Introduction and Control Basics Presented by Moayed Daneshyari 1 What is Matlab? Invented by Cleve Moler in late 1970s to

More information

SCIENTIFIC COMPUTING 7P-100-SCI

SCIENTIFIC COMPUTING 7P-100-SCI Engineering cycle, 2nd year 1 SCIENTIFIC COMPUTING 7P-100-SCI Lesson 1: General introduction and reminder on Matlab Hervé Sauer, Charles Bourassin-Bouchet, Mondher Besbes Ludivine Emeric, Léo Wojszvzyk

More information

Chapter 16 Numerical Linear Algebra

Chapter 16 Numerical Linear Algebra 16.1 Sets of Linear Equations Chapter 16 Numerical Linear Algebra MATLAB was developed to handle problems involving matrices and vectors in an efficient way. One of the most basic problems of this type

More information

Vector Spaces. 1 Theory. 2 Matlab. Rules and Operations

Vector Spaces. 1 Theory. 2 Matlab. Rules and Operations Vector Spaces Rules and Operations 1 Theory Recall that we can specify a point in the plane by an ordered pair of numbers or coordinates (x, y) and a point in space with an order triple of numbers (x,

More information

Matrix-Exponentials. September 7, dx dt = ax. x(t) = e at x(0)

Matrix-Exponentials. September 7, dx dt = ax. x(t) = e at x(0) Matrix-Exponentials September 7, 207 In [4]: using PyPlot INFO: Recompiling stale cache file /Users/stevenj/.julia/lib/v0.5/LaTeXStrings.ji for module LaTeXString Review: Solving ODEs via eigenvectors

More information

FF505 Computational Science. Matrix Calculus. Marco Chiarandini

FF505 Computational Science. Matrix Calculus. Marco Chiarandini FF505 Computational Science Matrix Calculus Marco Chiarandini (marco@imada.sdu.dk) Department of Mathematics and Computer Science (IMADA) University of Southern Denmark Resume MATLAB, numerical computing

More information

Phonon dispersion relation and density of states of a simple cubic lattice

Phonon dispersion relation and density of states of a simple cubic lattice Phonon dispersion relation and density of states of a simple cubic lattice Student project for the course Molecular and Solid State Physics by Eva Meisterhofer Contents 1 The linear spring model 3 1.1

More information

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP MATLAB sessions: Laboratory 4 MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP In this laboratory session we will learn how to. Use MATLAB solvers for solving scalar IVP 2. Use MATLAB solvers for

More information

Mon Jan Improved acceleration models: linear and quadratic drag forces. Announcements: Warm-up Exercise:

Mon Jan Improved acceleration models: linear and quadratic drag forces. Announcements: Warm-up Exercise: Math 2250-004 Week 4 notes We will not necessarily finish the material from a given day's notes on that day. We may also add or subtract some material as the week progresses, but these notes represent

More information

Numerical solution of ODEs

Numerical solution of ODEs Péter Nagy, Csaba Hős 2015. H-1111, Budapest, Műegyetem rkp. 3. D building. 3 rd floor Tel: 00 36 1 463 16 80 Fax: 00 36 1 463 30 91 www.hds.bme.hu Table of contents Homework Introduction to Matlab programming

More information

Solving systems of ODEs with Matlab

Solving systems of ODEs with Matlab Solving systems of ODEs with Matlab James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University October 20, 2013 Outline 1 Systems of ODEs 2 Setting Up

More information

Numerical Analysis Fall. Roots: Open Methods

Numerical Analysis Fall. Roots: Open Methods Numerical Analysis 2015 Fall Roots: Open Methods Open Methods Open methods differ from bracketing methods, in that they require only a single starting value or two starting values that do not necessarily

More information

These videos and handouts are supplemental documents of paper X. Li, Z. Huang. An Inverted Classroom Approach to Educate MATLAB in Chemical Process

These videos and handouts are supplemental documents of paper X. Li, Z. Huang. An Inverted Classroom Approach to Educate MATLAB in Chemical Process These videos and handouts are supplemental documents of paper X. Li, Z. Huang. An Inverted Classroom Approach to Educate MATLAB in Chemical Process Control, Education for Chemical Engineers, 9, -, 7. The

More information

Physics 584 Computational Methods

Physics 584 Computational Methods Physics 584 Computational Methods Introduction to Matlab and Numerical Solutions to Ordinary Differential Equations Ryan Ogliore April 18 th, 2016 Lecture Outline Introduction to Matlab Numerical Solutions

More information