J =2:3:19: This code will make an array j starting at 2 and increasing by 3, halting before or after
19, whichever comes first. J thus equals [2, 5, 8, 11, 14, 17].
K = 88: -2:77: This code will construct an array k that counts down from 88, decreases by 2, and
stops just shy of or below 77. The array will be empty because 88 is greater than 77, and k will
be [.
m =1:(1/5):4: This code will construct an array named m starting at 1 and increasing by 1/5 until
it reaches or exceeds 4. As a result, the value of m will be [1, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6,
2.8, 3.0, 3.2, 3.4, 3.6, 3.8].
This code, n=pi*[2:(-1/5):0], mixes colon notation and mathematical operations. It increases the
result of a colon notation, pi (), to the power. The colon notation begins at 2, decreases by -1/5,
and stops just shy of or below 0. Therefore, using a colon generates the values [2, 2.2, 2.4, 2.6,
2.8, 3.0]. Then, by raising to the power of each of these numbers, an array n containing the
powers of is created, looking like this: [9.8696, 10.182, 10.509, 10.853, 11.216, 11.600].
A) The expressions ones(2,5) and zeros(4,3) produce a 2x5 matrix of all ones and a 4x3 matrix of
all zeros, respectively.
A row of three ones, a range of numbers from 2 to 9 with a step of 2, and a row of four zeros are
concatenated into a single vector xx using the formula xx = [ones(1,3), [2:2:9], and zeros(1,4)].
The function c) xx (3:7) retrieves elements from the vector xx's index 3 to 7. You will be given
the numbers [1 2 4 6 8].
d) length(xx) yields the vector's length, which is 10 by the way.
e) The formula xx (3/7) = pi * (1:5) aims to give the element at index 3/7 a value.
You may use vector indexing and replacement to change the odd-indexed components of xx to
the value 77 as follows:
xx (1:2: end) = 77;
This will assign the value 77 to every element in xx with an odd index.
ACTIVITIES
IN
NUMERICAL METHODS
AND ANALYSIS
Submitted by:
De Castro Lysa Mae B.
Enriquez Enrique F.
Submitted to:
Mr. Jay Lexter D. Umali