You are on page 1of 2

ASSIGNMENT-2

1. Write a function called tri_area that returns the area of a triangle


with base b and height h, where b and h are the input arguments of the
function in that order.
2. Write a function with header [N] = myNOdds(A), where A is a one-
dimensional array of doubles and N is the number of odd numbers in A.
3. Write a function with header [S,V] = myCylinder(r,h), where r and h
are the radius and height of a cylinder, respectively, and S and V are
the surface area and volume of the same cylinder, respectively. Recall
that the surface area of a cylinder is 2πr2 +2πrh, and the volume is
πr2h. Assume that r and h are 1 × 1 doubles.
4. Recall that the hyperbolic sine, denoted by sinh, is . Write a
function with header [y] = mySinh(x), where y is the hyperbolic sine
computed on x. Assume that x is a 1 × 1 double.
5. Write a function with header [M] = myCheckerBoard(n), where M is an n
× n matrix with the following form:

Note that the upper-left element should always be 1. Assume that


n is a strictly positive integer.

6. Write a function with header [M1,M2] = mySplitMatrix(M), where M is a


matrix, M1 is the left half of M, and M2 is the right half of M. In
the case where there is an odd number
of columns, the middle column should go to M1. Hint: The size and cell
functions will be useful for this. Assume that M has at least two
columns.
7. Write a function called minimax that takes M, a matrix input argument
and returns mmr, a row vector containing the absolute values of the
difference between the maximum and minimum valued elements in each
row. As a second output argument called mmm, it provides the difference
between maximum and minimum element in the entire matrix. See the code
below for an example:

You might also like