You are on page 1of 1

Assignment 1(Mathematical Computing) (Due April 3, 2019)

1 The pH scale ranges from 0 to 14, inclusive. A solution with a pH of 7 is said to be


neutral, a solution with a pH greater than 7 is basic, and a solution with a pH less than 7
is acidic. Write a script that will prompt the user for the pH of a solution, and will print
whether it is neutral, basic, or acidic. If the user enters an invalid pH, an error message
will be printed.

2. If the Mach number is less than 1, the flow is subsonic; if the Mach number is equal to
1, the flow is transonic; if the Mach number is greater than 1, the flow is supersonic.
Write a script that will prompt the user to enter the Mach number and output the result
as subsonic, transonic or supersonic.

3. Write a function called”makemat” that will receive two row vectors as input
arguments and from them create and return a matrix with two rows. You may not
assume that the length of the vectors is known. Also the vectors may be of different
length. If that is the case, add 0’s to the end of one vector first to make it as long as the
other. For example your result will be:
>> makemat(1:4, 2:7)
Ans =
123400
234567

4. Write a for loop that will print the column of real number from 2.7 to 3.5 in steps of
0.2.

5. Write a function prodby3 that will receive a value of a positve integer n and will
calculate and return the product of the odd integers from 1 to n (or from 1 to n -1 if n is
even ). Use a for loop.

6. Write a function that will receive a matrix as an input argument, and will calculate
and return the overall average of all numbers in the matrix. Use loops, not built-in
functions, to calculate the average.

7. The following code was written by somebody who does not know how to use MATLAB
efficiently. Rewrite this as a single statement that will accomplish exactly the same thing
for a matrix variable mat.

[r c] = size(mat);
for i = 1: r
for j = 1:c
mat(i, j) = mat(i,j)*2
end
end

You might also like