# Lecture4 - Initializing Variables s s s s Explicitly list...

This preview shows pages 1–10. Sign up to view the full content.

Initializing Variables Explicitly list the values reads from a data file uses the colon (:) operator reads from the keyboard A = [1; 3; 5; 10]; B = [1 3 5; -6 4 -1] C = [2 3 5 1; 0 1 … (continuation) 1 -2; 3 5 1 -3] E = [A; 1; A]; F = [C(2,3); A]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
- = - - = 4 1 1 2 1 0 5 2 F 4 1 0 1 2 3 1 0 1 5 2 1 C Colon Operator Creating new matrices from an existing matrix C = [1,2,5; -1,0,1; 3,2,-1; 0,1,4] F = C(:, 2:3) = [2,5; 0,1; 2,-1; 1,4]
- - = - - = 1 2 3 1 0 1 E 4 1 0 1 2 3 1 0 1 5 2 1 C Colon Operator Creating new matrices from an existing matrix C = [1,2,5; -1,0,1; 3,2,-1; 0,1,4] E = C(2:3,:) = [-1 0 1; 3 2 -1]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Colon Operator Creating new matrices from an existing matrix C = [1,2,5; -1,0,1; 3,2,-1; 0,1,4] G = C(3:4,1:2) = [3,2; 0,1] = - - = 1 0 2 3 G 4 1 0 1 2 3 1 0 1 5 2 1 C
Colon Operator Variable_name = a:step:b time = 0.0:0.5:2.5 time = [0.0, 0.5, 1.0, 1.5, 2.0, 2.5] Negative increment values = 10:-1:2 values = [10, 9, 8, 7, 6, 5, 4, 3, 2]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
linspace Function linspace(x1, x2) gives 100 evenly spaced values 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 0.8000 1.0000 1.2000 Columns 8 through 11 1.4000 1.6000 1.8000 2.0000
logspace Function logspace( a, b, n ) generates a logarithmically 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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Special Matrices = = = = 1 1 1 1 1 1 1 1 ones(2,4) 1 1 1 1 1 1 1 1 1 ) 3 ( ones 0 0 0 0 0 0 zeros(3,2) 1 0 0 0 1 0 0 0 1 ) 3 ( eye
b a b a b a b a a b b a b a b a b a ab a a b a a b - + ± - + = ÷ - - - ; n subtractio and Addition \ \ division Left \ / ; * ; division and tion Multiplica / * Negation ^ tion

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern