Calculating areas:
• Itis known that the area of a circle is ^2and the volume of
𝜋𝑟
a sphere is 4/3 ^3.
𝜋𝑟
•Start your programme by taking the input of a radius r from
user and obtain the area of a circle with radius r and volume
of a sphere with radius r.
3.
Fun with numbers:
•Write a code that take three user-entered integers and
return them sorted (smallest to largest). To determine the
minimum and maximum numbers, use the min and max
commands. The centre number can be calculated by adding
the other three together values, minus the lowest and
maximum, to get a final value.
4.
Creating vectors
Row vector-Row vectors are created using square brackets with
elements separated by a comma or a space.
Column vector- Column vectors are created using square
brackets with elements separated by a semicolon (;).
Generating equally spaced vectors using colon
Generating vectors using linspace
5.
Mathematical operations
Sum ofvectors.
Difference of vectors.
For multiplication vectors must be of size r x n
and n x p.
Element by element multiplication.
Element by element division.
Element by element power.
Hands on practice
1.Creating row vector: Create a row vector x of odd numbers from 1 to 21
using the colon operator.
2. Creating column vector: Generate a column vector y to have 5 multiples of
12 in reverse order.
3. Mathematical operation on vector: Calculates the sum (s) and product (p)
of the elements of a vector v with v=[2 5 8 12 16] and cross verify your results.
4. Finding size of vector: Use size and length command to find the number of
elements in a vector v defined as v=[ 11 13 15 19 76 32 65].
8.
5. Working withvectors: Create two different vectors of the same
length as follows: first with first 6 multiples of 2 in reverse order and
another with 6 terms of A.P with difference of 3 and first term 6.
a) add them.
b) subtract them.
c) Perform element-by-element multiplication on them.
d) Perform element-by-element division on them.
e) Raise one of the vectors to the second power
9.
6. Extracting elementsof vectors: Create a vector A from 40 to 1 with a
decrement of 2. Extract the element at
a) Position 4
b) From fourteenth to last position.
c) Position third, seventh, twelfth and the last.
d) Invert the vector from end to start and store in another vector B.
e) Transpose the first five elements of vector A to get the output in
column vector with transpose command '
10.
7. Extracting elementsof vectors: Create a vector X with 5 points
between 1 to 10 (including the first and last); extract the third point.
8. Creation and extraction from vectors: Create a row vector y with 6
equally spaced elements in which the first element is 7 and the last
element is 40.
11.
Manipulating vector: Definea vector c with marks in different subjects
in last semester as follows:
c= [ 23 26 18 25 22]
Calculate the modified marks with
a) an increment of 3 marks to each value (Create a new vector D)
b) doubled the second subject marks,
c) divide the fourth subject marks by half.
d) find the difference between the earlier marks and the updated
marks.