6 views

Uploaded by johnanother

mat

- GAUSS-JORDAN.xlsx
- Linear Algebra
- Writing a Matrix into Row Echelon Form
- Dynamics of Offshore Structures_Chapter6_Structural Response
- HW1F11Solution
- a_mtt_ab_09_2
- LaTeX Math for Undergraduates
- FDMcode
- 1. 2. 3. 4. 5. 6. 7.
- appendix
- BM 503 Basic Mathematics for Biomedical Science W5
- MatLab Basics
- Assignment Bca 193
- Matrices
- Mat 31121SummerISyllabus2016
- Maths 001
- Electricity and Magnetism Individual Assignment
- Mat Lab Project 1
- MGM.02.4.Literacy
- HW 2 Solution.pdf

You are on page 1of 21

MATLAB

>> f = 'Miles ';

>> s = 'Davis'

>> x = [f s]

x =

Miles Davis

>> a = [1 2 3 4 5 ...

6 7 8]

a =

1

2

3

4

5

You cannot use an ellipsis within single quotes to continue a string. But you can

piece together shorter strings with ellipsis

>> quote = ['Any fool can make a rule,' ...

' and any fool will mind it']

quote =

Any fool can make a rule, and any fool will mind it

Initializing Variables

Read from a data file, or

Use the colon (:) operator, or

Read from the keyboard

A = [1; 3; 5; 10];

C = [2 3 5 1; 0 1

B = [1 3 5; -6 4 -1]

(continuation)

1 -2; 3 5 1 -3]

E = [A; 1; A];

F = [C(2,3); A]

Colon Operator

C = [1,2,5; -1,0,1; 3,2,-1; 0,1,4]

F = C(:, 2:3) (=> F = [2,5; 0,1; 2,-1; 1,4])

1

1

C

3

0

1

2 1

1

4

2

5

2

0

F

2 1

4

1

Colon Operator

C = [1,2,5; -1,0,1; 3,2,-1; 0,1,4]

E = C(2:3,:)

1

1

C

3

0

1

2 1

1

4

1

1 0

E

3 2 1

Colon Operator

G = C(3:4,1:2)

1

1

C

3

0

1

2 1

1

4

3 2

G

0

1

The colon operator : is useful in several contexts. It

can be used to create a linearly spaced array of

points using the notation

start:diffval:limit

where start is the first value in the array, diffval is the

difference between successive values in the array, and

limit is the boundary for the last value (though not

necessarily the last value).

>>1:0.6:3

ans =

1.0000

1.6000

2.2000

2.8000

Colon Operator

Variable_name = a:step:b

>> x = 0.0:0.5:2.5

>> x = 0.0:0.5:2.4

Negative increment

>> v = 10:-1:2

v = [10, 9, 8, 7, 6, 5, 4, 3, 2]

If diffval is omitted, the default value is 1:

>>3:6

ans =

3

4

5

6

To create a decreasing series, diffval must be negative:

>> 5:-1.2:2

ans =

5.0000

3.8000

2.6000

If start+diffval>limit for an increasing series or

start+diffval<limit for a decreasing series, an empty

matrix is returned:

>>5:2

ans =

Empty matrix: 1-by-0

To create a column, transpose the output of the colon

operator, not the limit value; that is, (3:6) not 3:6

linspace Function

between x1 and x2

x = linspace(x1, x2)

linspace(a, b, n) generate n equally spaced points

between a and b

x = linspace(a, b, n)

linspace(0,2,11)

ans =

Columns 1 through 7

0

0.2000

0.4000

0.6000

1.8000

2.0000

Columns 8 through 11

1.4000

1.6000

0.8000

1.0000

1.2000

logspace Function

equally spaced row vector

x = logspace(a,b,n)

logspace(a, b) generates 50 logarithmically

equally spaced points

x = logspace(a,b)

logspace(-4,2,7)

ans =

0.0001

0.0010

0.0100

0.1000

1.0000

10.0000

100.0000

There are several built-in functions to create

arrays:

zeros(r,c) will create an r row by c column

matrix of zeros

zeros(n) will create an n by n matrix of zeros

ones(r,c) will create an r row by c column

matrix of ones

ones(n) will create an n by n matrix one ones

eye(n) will create an n by n identity matrix

of the elementary matrices

Special Matrices

1 0 0

eye( 3) 0 1 0

0 0 1

0 0

zeros(3,2) 0 0

0 0

1 1 1

ones( 3) 1 1 1

1 1 1

1 1 1 1

ones(2,4)

1 1 1 1

In order of priority

S ymbol

Operation

MATLAB Form

^

Exponentiation a b

a^ b

Negation a

a

* /

Multiplication and division ab; a b a * b; a / b

b

\

Left division a \ b (Matrix inverse) a \ b

a

a b; a b

Example: x = (a + b*c)/d^2

count = count + 1

Order of Precedence of

Arithmetic Operations

The priority order can be overridden with parentheses

a=3; b=5; c=2;

y = -7.3^2

s1 = a-b*c

y =

s1 =

-7

s2=(a-b)*c

s2 =

-53.2900

y=(-7.3)^2

y =

53.2900

-4

priority than subtraction

priority than negation

Array Operations

element-by-element

MATLAB: C = A.*B;

C(1) A(1) * B(1);

C(2) A(2) * B(2);

C(3) A(3) * B(3);

C(4) A(4) * B(4);

C(5) A(5) * B(5);

Element-by-Element Operations

Symbol Operation

Scalar-array addition

Form

Ab

Example

[4, 6] 3 [7, 9]

.*

./

.\

.^

Ab

A B

A B

A. * B

A. / B

A. \ B

A. ^ B

[8,

[4,

[4,

[3,

[3,

[3,

[4,

Scalar-array subtraction

Array addition

Array subtraction

Array multiplication

Array right division

Array left division

Array exponentiation

3] 6 [2, 3]

6] [8, 3] [12, 9]

6] [8, 3] [ 4, 3]

6]. *[2, 3] [6, 18]

7]. / [8, 5] [3 / 8, 7 / 5] [0.375,1.400]

7]. \ [8, 5] [3 \ 8, 7 \ 5] [2.667,0.7143]

2]. ^ 3 [4 ^ 3, 2 ^ 3] [64, 8]

[5, 3]. ^ [2, 4] [5 ^ 2, 3 ^ 4 ] [25, 81]

1

2

3

a 3

b 4

a b 7

5

6

11

But a*b gives an error (undefined) because

dimensions are incorrect. Need to use .*

1* 2 2

a .* b 3 * 4 12

5 * 6 30

A 2 3 8 1

B 1 4 5

C A .* B 2 12 40 2

D A . / B 2 0.75 1.6 0.5

E A .^ 3 8 27

512 1

F ( 3 ).^ B 3 81 243 9

m n Matrices

2

3

4

1

A 1 : 4; - 1 : -1 : -4; 3 1 2 - 1 1 2 3 4

3

1

2 1

10

15

20

5

B A.* 5 5 10 15 20

15

5

10

5

8

27

64

1

C A.^ 3 1 8 27 64

27

1

8

1

Matrix Transpose

x 4 2 3 ;

4

x' 2

3

y 3 1 2

;

y' 1

- 2

4 8

4

12

x'* y 2 3 1 2 6 2

4

3

9

3 6

3

x * y' 4 2 3 1 ( 4 )( 3 ) ( 2 )( 1 ) 3( 2 ) 4

- 2

- GAUSS-JORDAN.xlsxUploaded byalvin bautista
- Linear AlgebraUploaded bymfeinber
- Writing a Matrix into Row Echelon FormUploaded byMatthew
- Dynamics of Offshore Structures_Chapter6_Structural ResponseUploaded bydavid gomeztagle
- HW1F11SolutionUploaded byVipin Nair
- a_mtt_ab_09_2Uploaded byMehdi
- LaTeX Math for UndergraduatesUploaded byAnna Bond
- FDMcodeUploaded byclhs8860
- 1. 2. 3. 4. 5. 6. 7.Uploaded bykannu23
- appendixUploaded bySaurabh Dixit
- BM 503 Basic Mathematics for Biomedical Science W5Uploaded byYasin Cotur
- MatLab BasicsUploaded byMuhammad Abdullah
- Assignment Bca 193Uploaded bydolon10
- MatricesUploaded byFerrick Gray
- Mat 31121SummerISyllabus2016Uploaded byNayil Arana
- Maths 001Uploaded byArivananthanMarimuthu
- Electricity and Magnetism Individual AssignmentUploaded byMurindanyi Sudi
- Mat Lab Project 1Uploaded byAngela
- MGM.02.4.LiteracyUploaded bypandoraradio22
- HW 2 Solution.pdfUploaded byHeather Tat
- MATLAB_Basics_4.pdfUploaded byShweta Sridhar
- Graphics2-MathsPrelimUploaded bysainathsaitowers
- Matrix ODEUploaded byipixuna
- Activity Creating a Matrix Report.pdfUploaded byRadnum
- c^M^MUploaded byvivek
- IntroductiontoMatlab_cse802Uploaded byAndrea Fields
- Lecture 03Uploaded bysofianina05
- 102 Syl l 0607 SpringUploaded byErwin Huberto Callang Rivera
- Improved Solution for Potential Flow About Arbitrary A Xi Symmetric Bodies by the Use of a Higher-Order Surface Source MethodUploaded bymfregeau3654
- Arrays_2016__last (1)Uploaded byعثمان بانافع

- Lab 1 Prelab Reading - OxidationUploaded byjohnanother
- pf-kcUploaded byjohnanother
- 6-7-FDMUploaded byjohnanother
- MATLAB-1Uploaded byjohnanother
- Chap 1 Floating Point RepresentationUploaded byjohnanother
- AA283 Aircraft and Rocket Propulsion Ch 10 BJ Cantwell(1)Uploaded byjohnanother
- Graduate FaUploaded byjohnanother

- 7-4 Solving Logarithmic Equations and InequalitiesUploaded byEnas Basheer
- MITRES_6_007S11_hw05_solUploaded byLenin Kumar
- Syllabus_S_2009-10Uploaded byBachir El Fil
- 6 4 vectors and dot products-0Uploaded byapi-213604106
- A Fourier Pseudospectral Method for Some Computational Aeroacoustics ProblemsUploaded bygarridolopez
- 5 Example - Thin Airfoil TheoryUploaded bybatmanbittu
- Methods for drawing shear-moment diagrams-RH5001A53 Atish Kumar CIV 207Uploaded byAtish Kumar
- Influence Line Diagram calculationUploaded byAmanuel Q. Mulugeta
- Assignment 2 ECEUploaded byBRAHMA REDDY AAKUMAIIA
- sylow'sUploaded byJohn
- 07 FP2 Mock PaperUploaded bychequillas
- 1903.11576v1.pdfUploaded byAskar Myktybekov
- Mat 8050Uploaded byFrancis Valenti
- System Dynamics Ch3 The State Space Equations and Their Time Domain Solution.docUploaded byfitriafiadi
- Numerical Analytical Computational Mechanics Analysis 1420093568Uploaded bycanwee92
- B-spline - Chapter 4.pdfUploaded byMarius Diaconu
- Fourier Series.pdfUploaded byMark Lewis Sy
- hr_om11_modB_GE.pptUploaded bySeng Soon
- Catastrophe TalkUploaded bybadanppsdmk
- 11 ParityUploaded bylizvebe
- ECE576_Spring2014_Lect26 (1)Uploaded bywillbh
- 06163523Uploaded bySwapnil Kanade
- Exercises to Learn Scilab BasicsUploaded byAshwith Rego
- 0673 Chapter 6Uploaded bysubash1111@gmail.com
- Randomized Approximation Algorithms for Set MulticoverProblems with Applications to Reverse Engineering of Protein andGene NetworksUploaded bysysbio10
- Time History Ground Motion Scaling in EtabsUploaded byRaleigh Gesulga Labarrete
- Continuous Prob DistributionUploaded byHaris Baharrudin
- AP Calcab Derviatives Cw Hw 2014-12-07Uploaded byMax Cortezi
- Numerical Method for Incompressible FlowUploaded byKian Chuan
- Understanding the Fast Fourier TransformUploaded byAnonymous UZ5xA8