You are on page 1of 1

Computer Applications for Mechatronics

Attach the solutions as m.file for each question in addition to screenshots of your screen

1. Suppose Z is a matrix. Write a matlab code to replace all the diagonal elements with 5.

2. Write a user-defined function that calculates grade point average (GPA) on a scale
of 0 to 4, where, A=4, B=3, C=2, D=1 and E=0. For the function name and
arguments use av = GPA(g,h). The input argument g is a vector whose elements are
letter grades
A, B, C, D, or E entered as strings. The input argument h is a vector with the
corresponding credit hours. The output argument av is the calculated GPA.
For this case the input arguments are:
g=[‘BACEABDB’] and h=[3 4 3 4 3 4 3 2].

3. Write a user defined function called test that tests each number in a vector v and
returns one of these messages according to the state of the number:
‘the number is odd and divisible by 3’
‘the number is odd’
‘the number is divisible by 3’
‘the number is not odd and not divisible by 3’

You might also like