GSU 07201 TUTORIAL SHEET
General Studies Department-Computing Using Mathematical Software Module 1
1. Write a program that calculates Fabonacii series in which every number is generated by sum of
two previous terms. For example:
1 2 3 5 8 13 21 · · · n
2. The height and speed of a projectile (such as thrown ball) launches with speed v0 at an angle A
to the horizontal are given by
h(t) = v0tsinA − 0.5gt2
v(t) = v2
0 − 2v0gtsinA + g2t2
where g is the acceration due to gravity. The projectile will strike the groung when h(t) = 0, which
gives the time to hit, thit =
2v0sinA
g
. Suppose that A = 40◦
, v0 = 20ms−1
and g = 9.81ms−2
.
Use the MATLAB relational and logical operators to find the time when the height is not less
that 6m and the speed is simultaneously not greater than 16ms−1
. Note that graphical method
would be used but the accurate of the results would be limited with the ability to pick points off
the graph and it is time consuming.
3.
4. It has been said that there are two unpleasant and unavoidable facts of life in any country;
death and income tax. A very simplified version of how income tax is calculated in one of the
Africans’country is based on the following table:
Taxable income Tax payable
$10000 or less 10% of taxable income
Between $10000 and $20000 $1000+20% of amount by which taxable income exceeds $10000
More than $20000 $3000+50% of amount by which taxable income exceeds $20000
For example, the tax payable on a taxable income of $30000 is given by
$3000 + 50% of ($30000 − $20000) = $8000.
Develop a MATLAB program using loop with an elseif to calculate the income tax on the
following taxable income in dollars: 5000,15000,30000 and 50000.
5. By using if-elseif-else statement write a program to check whether a given number is greater
than or equal to 50. Test your program with numbers 23, 50 and 98.
6. Plot a bar graph to show the comparison of average temperature in the cities A, B and C for the
months from September to February of the data given in the table below:
Month City A City B City C
September 31 28 24
October 29 26 22
November 28 25 20
December 27 24 16
January 26 22 17
February 29 25 20
Label the x-axis as Months from September to February and the y-axis as Temperature in Celsius,
include the legend for cities and the title of your graph should read as Temperature of city A, B
and C for Months from September to February. Copy the codes and the graph displayed into your
answer booklet.
7. Develop a program which determines whether the given number is even or odd. The criteria
used in this programme is that the number is divided by 2 and remainder is calculated. If the
remainder is found to be equal to zero, then the number is even, otherwise the number is said to
be odd. Test your program by using 39, 2910 and 8455.
1Mbitila A.S.(Module tutor)
1
8. Prepare a MATLAB program which uses the compound if-statement which compares the age
of the students, whether it lies between 5 and 15 years. If the age is between this range, then it
printed as being permitted to appear for the contest, otherwise it is not permitted to appear for
the contest. Verify your program by using age of 3, 10 and 20.
9. Plot y = coshx and y = 0.5ex
on the same plot for for 0 ≤ x ≤ 2. Use different line types and
legend to distinguish the curves. Label the plot appropriately.
10. In meteorology, the Clausius-Clapeyron equation is employed to determine the relationship
between saturation water vapour pressure and atmospheric temperature.This is an important
component of weather prediction for irrigation purposes when the actual partial pressure of water
in the air is known. The Clausius-Clapeyron equation is
ln
P0
6.11
=
∆Hv
Rair
×
1
273
−
1
Tk
where P0
is the saturation vapour pressure for water in mbar, ∆Hv is the latent heat of vapor-
ization for water, 2.453 × 106
Jkg−1
, Rair is the gas constant for moist air, 461Jkg−1
and T is the
temperature in kelvins (K). It is rare that temperature on the surface of the earth are lower than
−60◦
F or higher than 120◦
F. The formula to convert Fahrenheit degrees into kelvin degrees (Tk)
is given by
Tk =
(Tf + 459.6)
1.8
where Tf is temperature in Fahrenheit. Use the Clausius-Clapeyron equation to find the saturation
vapour pressure in the range from −60◦
F to 120◦
F in the increment of 20◦
F. Present your results
as a table of Fahrenheit temperatures and Saturation vapour pressures. Column heading of your
table are not necessary.
11. Design a program with nested if-statement in which the price and the number of products
purchased by the customer is supplied. If the price is more than 5000 and the number of products
purchased are more that 5, then the discount is paid as 5%, otherwise if the price of the product
is less than 5000, then the discount given on products is zero. Verify the performance of your
program at three different stages: 10000 price with 15 number of items, 4000 with 20 number of
items and 250000 price and 2 number of items.
12. Consider the following square matrix
x =




4 90 85 75
2 55 65 75
3 78 82 79
1 84 92 93



.
Write down the MATLAB code to find:
(a) the maximum value in each column
(b) the row in which maximum value in (a) above occur
(c) the maximum value in each row (you will have to transpose the matrix to answer this
question)
(d) the column in which maximum value in (c) above occur
(e) the maximum value of the entire table or matrix
(f) the mean value in each column
(g) the median for each column
(h) the mean value of each row
(i) the median value for each row
(j) the mean for the entire matrix
(k) the standard deviation of each column
(l) the variance for each column
(m) the square root of variance you found for each column
13. Use the subplot command to sketch the graphs of the functions; y = e−1.2x
sin(10x + 5) for
0 ≤ x ≤ 5 and y = |x3
− 100| for −6 ≤ x ≤ 6 in the same figure.
2
14. MATLAB has overlay plot capability to create overlay plots. Use this capability to plot a variable
x = 0 : 10 : 30 against matrix
A =




4 6 8 10
2 6 10 14
1 2 3 5
18 15 12 8




15. Plot y = sinhx and y = 0.5ex
on the same plot for for 0 ≤ x ≤ 2. Use solid line type for each,
the gtext command to label the sinhx curve, the text command to label the 0.5ex
curve. Label
the plot appropriately.
16. Create a function named kubwa which should be written in a file named kubwa.m. The function
created must takes five numbers as argument and returns the maximum of the numbers.
3

MATLAB review questions 2014 15

  • 1.
    GSU 07201 TUTORIALSHEET General Studies Department-Computing Using Mathematical Software Module 1 1. Write a program that calculates Fabonacii series in which every number is generated by sum of two previous terms. For example: 1 2 3 5 8 13 21 · · · n 2. The height and speed of a projectile (such as thrown ball) launches with speed v0 at an angle A to the horizontal are given by h(t) = v0tsinA − 0.5gt2 v(t) = v2 0 − 2v0gtsinA + g2t2 where g is the acceration due to gravity. The projectile will strike the groung when h(t) = 0, which gives the time to hit, thit = 2v0sinA g . Suppose that A = 40◦ , v0 = 20ms−1 and g = 9.81ms−2 . Use the MATLAB relational and logical operators to find the time when the height is not less that 6m and the speed is simultaneously not greater than 16ms−1 . Note that graphical method would be used but the accurate of the results would be limited with the ability to pick points off the graph and it is time consuming. 3. 4. It has been said that there are two unpleasant and unavoidable facts of life in any country; death and income tax. A very simplified version of how income tax is calculated in one of the Africans’country is based on the following table: Taxable income Tax payable $10000 or less 10% of taxable income Between $10000 and $20000 $1000+20% of amount by which taxable income exceeds $10000 More than $20000 $3000+50% of amount by which taxable income exceeds $20000 For example, the tax payable on a taxable income of $30000 is given by $3000 + 50% of ($30000 − $20000) = $8000. Develop a MATLAB program using loop with an elseif to calculate the income tax on the following taxable income in dollars: 5000,15000,30000 and 50000. 5. By using if-elseif-else statement write a program to check whether a given number is greater than or equal to 50. Test your program with numbers 23, 50 and 98. 6. Plot a bar graph to show the comparison of average temperature in the cities A, B and C for the months from September to February of the data given in the table below: Month City A City B City C September 31 28 24 October 29 26 22 November 28 25 20 December 27 24 16 January 26 22 17 February 29 25 20 Label the x-axis as Months from September to February and the y-axis as Temperature in Celsius, include the legend for cities and the title of your graph should read as Temperature of city A, B and C for Months from September to February. Copy the codes and the graph displayed into your answer booklet. 7. Develop a program which determines whether the given number is even or odd. The criteria used in this programme is that the number is divided by 2 and remainder is calculated. If the remainder is found to be equal to zero, then the number is even, otherwise the number is said to be odd. Test your program by using 39, 2910 and 8455. 1Mbitila A.S.(Module tutor) 1
  • 2.
    8. Prepare aMATLAB program which uses the compound if-statement which compares the age of the students, whether it lies between 5 and 15 years. If the age is between this range, then it printed as being permitted to appear for the contest, otherwise it is not permitted to appear for the contest. Verify your program by using age of 3, 10 and 20. 9. Plot y = coshx and y = 0.5ex on the same plot for for 0 ≤ x ≤ 2. Use different line types and legend to distinguish the curves. Label the plot appropriately. 10. In meteorology, the Clausius-Clapeyron equation is employed to determine the relationship between saturation water vapour pressure and atmospheric temperature.This is an important component of weather prediction for irrigation purposes when the actual partial pressure of water in the air is known. The Clausius-Clapeyron equation is ln P0 6.11 = ∆Hv Rair × 1 273 − 1 Tk where P0 is the saturation vapour pressure for water in mbar, ∆Hv is the latent heat of vapor- ization for water, 2.453 × 106 Jkg−1 , Rair is the gas constant for moist air, 461Jkg−1 and T is the temperature in kelvins (K). It is rare that temperature on the surface of the earth are lower than −60◦ F or higher than 120◦ F. The formula to convert Fahrenheit degrees into kelvin degrees (Tk) is given by Tk = (Tf + 459.6) 1.8 where Tf is temperature in Fahrenheit. Use the Clausius-Clapeyron equation to find the saturation vapour pressure in the range from −60◦ F to 120◦ F in the increment of 20◦ F. Present your results as a table of Fahrenheit temperatures and Saturation vapour pressures. Column heading of your table are not necessary. 11. Design a program with nested if-statement in which the price and the number of products purchased by the customer is supplied. If the price is more than 5000 and the number of products purchased are more that 5, then the discount is paid as 5%, otherwise if the price of the product is less than 5000, then the discount given on products is zero. Verify the performance of your program at three different stages: 10000 price with 15 number of items, 4000 with 20 number of items and 250000 price and 2 number of items. 12. Consider the following square matrix x =     4 90 85 75 2 55 65 75 3 78 82 79 1 84 92 93    . Write down the MATLAB code to find: (a) the maximum value in each column (b) the row in which maximum value in (a) above occur (c) the maximum value in each row (you will have to transpose the matrix to answer this question) (d) the column in which maximum value in (c) above occur (e) the maximum value of the entire table or matrix (f) the mean value in each column (g) the median for each column (h) the mean value of each row (i) the median value for each row (j) the mean for the entire matrix (k) the standard deviation of each column (l) the variance for each column (m) the square root of variance you found for each column 13. Use the subplot command to sketch the graphs of the functions; y = e−1.2x sin(10x + 5) for 0 ≤ x ≤ 5 and y = |x3 − 100| for −6 ≤ x ≤ 6 in the same figure. 2
  • 3.
    14. MATLAB hasoverlay plot capability to create overlay plots. Use this capability to plot a variable x = 0 : 10 : 30 against matrix A =     4 6 8 10 2 6 10 14 1 2 3 5 18 15 12 8     15. Plot y = sinhx and y = 0.5ex on the same plot for for 0 ≤ x ≤ 2. Use solid line type for each, the gtext command to label the sinhx curve, the text command to label the 0.5ex curve. Label the plot appropriately. 16. Create a function named kubwa which should be written in a file named kubwa.m. The function created must takes five numbers as argument and returns the maximum of the numbers. 3