[PDF] [PDF] MATLAB tutorial - Faculty Washington

(MATLAB) How does a command or function work? >> help sqrt SQRT Square root SQRT(X) is the square root of the elements of X Complex results are 



Previous PDF Next PDF





[PDF] Lectures on Matlab

Most of the usual mathematical functions are implemented in MATLAB >> cos(0) Write a script file to calculate the squares of the integers up to 20 A script 



[PDF] Notes introductives à Matlab

On peut utiliser Matlab, soit en mode en ligne, c'est-à-dire saisir des commandes dans la fenêtre d' Matrix functions - numerical linear algebra Square root



[PDF] Initiation au logiciel Matlab

3 PROGRAMMATION ET M-FILE FUNCTIONS axis('square') présente le graphe dans un carré au lieu du rectangle habituel 7 4 Les commandes figure, hold 



[PDF] MATLAB tutorial - Faculty Washington

(MATLAB) How does a command or function work? >> help sqrt SQRT Square root SQRT(X) is the square root of the elements of X Complex results are 



[PDF] Getting Started with MATLAB

square is (n3 + n)/2 The magic Function MATLAB actually has a built-in function that creates magic squares of almost any size Not surprisingly, this function is 



[PDF] MATLAB® Primer

MATLAB and Simulink are registered trademarks of The MathWorks, Inc See MATLAB actually has a built-in function that creates magic squares of almost any  



[PDF] MATLAB Tutorial

DOC: DOC FUN displays the help browser for the MATLAB function FUN (e g doc help) You can invoke matrix is defined inside a pair of square brackets ([])



[PDF] Short Matlab Manual

To use this function to calculate the area and circumference of a rectangle with sides 5 and 7, and for a square with side 6, we type the following at the Matlab 



[PDF] MATLAB Programming

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and xPC To create a 5-by-5 magic square matrix, use the magic function as shown eye



[PDF] Matlab Guide - Cleveland State University

15 sept 2008 · tary math functions are in matlab\elfun, so I type help matlab\elfun than or equal to 100 that have integer square roots It shows you how to 

[PDF] functional structure

[PDF] fundamentals of corporate finance pdf

[PDF] fundamentos de administracion y gestion

[PDF] fundamentos de gestión empresarial

[PDF] fundamentos de gestion empresarial definicion

[PDF] fundamentos de gestion empresarial enfoque basado en competencias pdf

[PDF] fundamentos de gestion empresarial enfoque basado en competencias pdf gratis

[PDF] fundamentos de gestion empresarial julio garcia del junco pdf

[PDF] fundamentos de gestion empresarial libro

[PDF] fundamentos de gestion empresarial mc graw hill pdf

[PDF] fundamentos de gestión empresarial pearson pdf

[PDF] fundamentos de gestion empresarial unidad 1

[PDF] fundamentos de marketing kotler 13 edicion pdf

[PDF] fundamentos de marketing kotler 14 edicion pdf

[PDF] fundamentos de marketing kotler 8va edicion pdf

Introduction to MATLAB

Very sophisticated "graphing calculator"

High-level programming language for sci-

entific computing

Similar to PYTHON, with more built-in BUT

not open-source vs. c or FORTRAN, many built-in com- mands, less-complex syntax vs. c or FORTRAN, Interpreted language (code translated during run), with some pre- compiled functions

IF used carefully, good balance of speed

and ease of use

Our introduction follows, in part, section 1

of the excellent "An introduction to Matlab for dynamic modeling" by Guckenheimer and Ell- ner: www.cam.cornell.edu/ dmb/DMBsupplements.html, as well as mate- rial from Prof. Mark Goldman, UC DavisLaunch matlab!

Command window (graphing calculator) mode

>> 1+3 ans = 4

Assigningvaluestovariables

>> a=1+3 a = 4

Displaying values

>> a a = 4

Suppressing display of output in MATLAB

>> a=1+3; 1

BASIC OPERATIONS:

Arithmetic

/ (divide) (multiply)

ˆ (exponent)

abs(x) (absolute value) cos(x), sin(x), tan(x) exp(x) exponential function eˆx log(x) log to base e sqrt(x) square root

The latter are built-in functions

>> a = sqrt(5) a = 1.4142 >> a=2 ; b=4 ; c=aˆb c = 16There are also some built-in variables >> pi ans = 3.1416 >> cos(pi) ans = -1 2

FUNDAMENTAL PROGRAMMING SYNTAX:

LHS = RHS

value RHS assigned to LHS, NOT other way around >> c=2 c = 2 >> 2=c ??? 2=c Error: The expression to the left of the equals sign is not a valid target for an assignment.

Another example:

>> a=2;b=4; >> a=b; >> a,b a = 4 b = 4 >> a=2;b=4; >> b=a; >> a,b a = 2 b = 2 3

Variable names:

>> a1=2 >> my_favorite_variable_number_2=4

VALID: Letter followed by letters, numbers, un-

derscore character.

NOTE! capitalization matters.A6=a!!

NOT VALID:

>> my_favorite_variable#2=4 ??? my_favorite_variable#2=1 >> 2a=1

Error: Unexpected MATLAB expression.

And using periods gives a different, more

advanced type of variable (data structure) that we won"t discuss now >> my.favorite.variable.name=1 my = favorite: [1x1 struct]ORDER OF OPERATIONS:

PEMDAS

parenthesis exponentiation multiplication division addition subtraction

Say we want:a= 2; b= 4; c=aa+b

>> a=1 ; b=4 ; c=a/a+b c = 5 >> a=1 ; b=4 ; c=a/(a+b) c = 0.2000 !! When in doubt, put lots of parentheses !! 4

CHECK: What do you get for the below, and why?

>> a=1 ; b=4 ; c =0 ; >> d=a/0+b >> d=a/(0+b) >> d=-aˆ2 >> d=(-a)ˆ2 5

Check: what variables stored in memory:

whoscommand (MATLAB) >> whos

Name Size Bytes Class Attributes

a 1x1 8 double b 1x1 8 double c 1x1 8 double OR look in "workspace" to see variables and values

OR just type variable at command line

>> a a = 1 GOOD PRACTICE: clear variables before starting to program (MATLAB:) >> clear all >> whos

Commands stored in memory:

See command history, or just hit "up arrow"

6 Representation of numbers in scientific computing: finite precision

Standard: IEEE floating point arithmetic.

Important feature - finite precision: approx 16 significant digits

Display more digits:

>> a=0.1 a =

0.1000

>> format long >> a a = 0.100000000000000

Roundoff error:

>> a=4/3 ; b=a-1 ; c = (3 *b)-1 c = -2.220446049250313e-16 7

OVERFLOW AND UNDERFLOW:

Maximum number:10308

Minimum number:10308

Overflow:

>> a=10ˆ400 a = Inf

Underflow

>> a=10ˆ-400 a = 0

Another special number: not defined

>> 0/0 ans = NaN 8

HELP !! (MATLAB)

How does a command or function work?

>> help sqrt

SQRT Square root.

SQRT(X) is the square root of the elements of X. Complex results are produced if X is not positive.

See also sqrtm, realsqrt, hypot.

Reference page in Help browser

doc sqrt >> doc sqrt Thanks anyway, but what SHOULD I be looking up? the lookfor command >> lookfor exponent

EXP Exponential.

EXPINT Exponential integral function.

EXPM Matrix exponential.

HELP !!: Remember Google and stackoverflow, etc are your friends 9

VECTORS

A vector value is just a list of scalar values.

Arranged horizontally into arow vector:

~x= (6 12 5):(1)

Or vertically into acolumn vector:

~x=0 @6 12 51
A :(2)

In MATLAB, row vector:

>>x=[6 12 5] x = 6 12 5 OR >>x=[6 ,12 ,5] x = 6 12 5 10

In MATLAB, column vector:

>>x=[6 ; 12 ; 5] x = 6 12 5 Thetransposeoperation switches between row and column vectors. This is given by dot prime in MATLAB. That is, in MATLAB: >> y=x." 11

Easy way to make (row) vectors [MATLAB, ]

x = start : increment : end >> x=0:1:10 x =

0 1 2 3 4 5 6 7 8 9 10

>> x=1:.1:1.5 [MATLAB] x =

1.0000 1.1000 1.2000 1.3000 1.4000 1.5000

Accessing vector elements (or components):

MATLAB:

>> x5=x(5) x5 = 1.4000 >> x(7) ??? Index exceeds matrix dimensions.

Indexing starts with 1; x(0) does not work.

12

Exercise 0.1: Have MATLAB compute the values of

1. Mak ea list n umbersspaced b y0.2, betw eena minim umv alueof 1 and a maxim umv alue of 20. Assign that list to the variable namemyvector. 2. use help to look up the linspacecommand, and repeat the previous command using linspace 3. pic kout the 4th v alueof myvectorand assign it to the variable namefourthelement 13

TWO BASIC OPERATIONS ON VECTORS:

Multiplication by scalar

c~x=0 @x 1 x 2 x 31
A =0 @cx 1 cx 2 cx 31
A ; that is,xj!cxj

Matlab *

>> x=[1;2;3] ; 3 *x ans = 3 6

9Addition of two vectors

~x+~y=0 @x 1+y1 x 2+y2 x 3+y31 A

Subtraction similar

Works the same for row and column vectors

Matlab + and -

>> x=[1;2] ; y=[0;-2]; z=x+y z = 1 0 >> z+ [2 2] ??? Error using ==> plus

Matrix dimensions must agree: add row +

row or col + col

CAUTION! Multiplication of vectors does NOT

work the same way ... more later (matrix- vec- tor multiplication) 14

Matrices

Think of matrices asNMtables of num-

bers N rows, M columns

MATLAB:

A=A1;1A1;2

A

2;1A2;2

entries A(n,m) >> A=[1,2,3 ; 4 6 7 ; 1 3 4] A = 1 2 3 4 6 7 1 3 4 >> A23=A(2,3)

A23 = 7

N-element col. vector: N, M=1

M-element row. vector: N=1, M

Otherwise, we will mostly consider square

matrices (N=M)Exercise 0.2: Have MATLAB compute the values of 1.

3*A. F romthis ,wr itedo wna r ulef orwhat

matrix multiplication by a single number (scalar) means. 2.

A+A. F romthis ,wr itedo wna r ulef orwhat

summing matrices means. 3.

A*A. F romthis ,conclude that m ultiplying

two matrices (like multiplying two vectors) means something very different indeed (and to be cautious about)! 4.

Exper imentwith the command .*with both

vectors and matrices. What does THIS command do? 15

FUNDAMENTAL CONCEPT: Matrix-vector multiplication

A1;1A1;2

A

2;1A2;2

x1 x 2 =x1A1;1 A 2;1 +x2A1;2 A 2;2 e.g. 1 1 1 2 1 2 =3 5

In general,

0 @j j a 1an j j1 A0 @x 1... x n1quotesdbs_dbs7.pdfusesText_13