# MA5233: Write down the MATLAB conversion program that prompts user to input number as any integer and units as string.: Computational Mathematics Assignment, NUS

Question 1

(a) Convert the 4275 octal number to (6 marks)

(i) Binary
(ii) Decimal

(b) Calculate the following: (6 marks)

(i) 10268 + 53258
(ii) 11112 * 1012
(iii) FECA16 + 87B616

Question 2

a) Given that
𝑋 = 𝑃𝑄 + 𝑄. 𝑅 + (𝑃. 𝑅 + 𝑃̅ + 𝑅̅.𝑄)

i) Construct a logic circuit diagram for the above Boolean expression.

ii) Construct a truth table for the above Boolean expression.

iii) Simplify the Boolean expression of part (i).

Question 3

(a) A can of soda at temperature (Ti) 25◦ C is placed in a refrigerator, where the
ambient temperature F is 10◦ C. We want to determine how the temperature of
the soda changes over a period of time t from 0 to 100 minutes. A standard way of approaching this type of problem is to subdivide the time interval into a
number of small steps, each of duration dt. If Ti is the temperature at the
beginning of step i, the following model can be used to determine Ti+1:

Ti+1 = Ti + K dt (F − Ti)

where K is the conduction coefficient, a parameter that depends on the
insulating properties of the can and the thermal properties of the soda.
Assume that units are chosen so that time is in minutes and that an interval dt
= 1 minute provides sufficient accuracy. Write MATLAB script to compute,
display, and plot this update process for K = 0.05.

(b) Write a MATLAB program to compute the sum of the first 15 terms in the
series 5𝑘 2 − 2𝑘 , where k is from 1 to 15

Question 4

Smart Plotter Program – Design an application that displays a menu to ask the user to choose whether to:

(a) Plot the relationship between the temperature and time using bar chart using the following instructions

− Load a file that contain an array of 10 temperatures

− Load a file that contain an array of 10 corresponding time values at which
the temperatures were taken.

− Determine the mean temperature and print the output.

(b) The variable t represents time in seconds, and the dimensionless variable y
represents the pressure difference across the aortic valve, normalised by a
constant reference pressure.

Write Matlab command to plot this function y(t) for from 𝟎 ≤ 𝒕 ≤ 𝟐𝟎.

(c) Quit the Smart Plotter

The user can choose then proceed to plot a simple 2D line, a scatter plot or bar
chart. The program will continue displaying the menu to allow the user to choose until the user chooses to quit the application.

Question 6

(a) Write down the MATLAB conversion program that prompts user to input
number as any integer and units as string.

– If the user input units as inch, then the given number is converted to
centimeters using the formula centimetres = number * 2.54.

– If the user input units as metre, then the given number is converted to
centimetres using the formula centimetres = number * 100.

– If the user input units as any other string, then display unit is unknown.

(b) Write a MATLAB program to calculate the taxi fare for the following:

There are two types of taxis:

• Online taxi: It can be booked by using an online app from phones

• Classic taxi: It can be booked anywhere on the road

The online taxis cost Oc for the first km and Od for every km afterward. The
classic taxis travel at a speed of Cs km per minute. The costs of classic taxis
are Cb, Cm, and Cd that represents the base fare, cost for every minute that
is spent in the taxi, and cost for each kilo meter that you ride.

that you are required to pay. The distance from your home to the school is D.
You are required to select whether you want to use online or classic taxis to
go to your school. If both the taxis cost the same, then you must use an online
taxi.

Input

• Single integer D that denotes the distance from your house to the school
• Three integers Oc, Of, and Od
• Four integers Cs, Cb, Cm, and Cd

If you select an online taxi to travel, then print a string ‘Online Taxi’. Otherwise,
select ‘Classic Taxi’. You can print this string in a new, single line.

Formula:
online taxi cost = Oc + (D – Of) *Od
classic taxi cost = Cb + (D/Cs) *Cm + D *Cd