Download presentation
Presentation is loading. Please wait.
Published byWilfrid Scot Bennett Modified over 9 years ago
1
Vectors Lecture 11: Supporting Material Dr Kathryn Merrick Tuesday 7 th April, 2009
3
Overview What is a vector? Creating vectors Accessing vectors Manipulating data in vectors Implicit vectorisation Reference: text book Ch 5
4
A Motivating Experiment:
5
Creating Vectors
6
Listing Elements >> my_vector = [1 4 30 2 6]; or >> my_vector = [1, 4, 30, 2, 6];
7
>> my_vector = [1:10]; or >> my_vector = [1:0.1:10]; or >> my_vector = 1:0.1:10; Using the Colon Operator :
8
Using a Built-in Function >> x = 0:0.1:2*pi; >> my_vector = sin(x); Or >> x = [0:10]; >> my_vector = x*5;
9
Using linspace or logspace linspace(x, y) generates 100 equally spaced points between x and y >> my_vector = linspace(1, 100) linspace(x, y, n) generates n equally spaced points between x and y >> my_vector = linspace(1, 100, 10)
10
Column Vectors >> a = [1; 2; 3; 4; 5] >> a = [1 2 3 4 5]
11
Transposing a Row Vector >> a = [1 2 3 4 5] a = 1 2 3 4 5 >> b = a' b = 1 2 3 4 5
12
Demo 1: Accessing Data in Vectors
13
Accessing One or More Values Accessing Individual Values >> value = my_vector(5); Accessing Multiple Values >> values = my_vector([5 10 15]);
14
Demo 2: Manipulating Vectors
15
Manipulating Vectors: Basic Maths
16
Scalar-Array Maths Example >> x = [0:10]; y = x + 5; Or >> x = [0:10]; y = x * 5;
17
Basic Array Maths Addition >> a = [2 3]; >> b = [4 5]; >> c = a + b c = 6 8 Subtraction >> a = [2 3]; >> b = [4 5]; >> c = a - b c = -2 -2
18
Basic Array Maths Multiplication >> a = [2 3]; >> b = [4 5]; >> c = a.* b c = 8 15 Division >> a = [2 3]; >> b = [4 5]; >> c = a./ b c = 0.5 0.6 Power >> a = [2 3]; >> b = [4 5]; >> c = a.^ b c = 16 243
19
Summary After today’s lecture you should be able to: Create and access data in vectors Manipulate data in vectors using loops or implicit vectorisation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.