Anda di halaman 1dari 2

ASSIGNMENT 2

INSTRUCTION
1.
2.
3.
4.
5.

Answer ALL questions using MATLAB.


Submit the solution in form of M-files/script files format to khairulirfan@salam.uitm.edu.my
Due date is on 13 May 2014 (Tuesday) before 5.00 pm.
Late submission, will be penalizes 10% from the total mark for each day.
Please name each file with your name, student id & question no. (e.g
Syafiq_1234567890_Q1).
6. Please put all the solution in one folder by naming it as Assignment 2 - Your Name and
compress it using winRAR application before sending it.
7. Name the email subject of your submission ASSIGNMENT 2 Your Name (e.g.
ASSIGNMENT 2 Syafiq)
8. Any sense of copying or plagiarism will result in getting zero.
QUESTION
Q1: Consider the function y = x2e-4x. Write a Matlab scripts that will produce a smooth graph of this
function on the interval x = [0,3]
Q2: Use fplot command to plot the function: f(x) = 0.01x5 0.03x4 + 0.4x3 2x2 6x + 5 in the domain
-4 x6
Q3: Write an if statement that prints boo if number is between 12 and 17, inclusive.
Q4: Write code that prints blue for numbers less than 5, green for numbers from 5 to 10
inclusive, and mauve for numbers higher than 10.
Q5: Using nested for loop to generate a matrix that has elements shown below (without typing the
number explicitly):

12 8 4
A 14 10 6
16 12 8

0
2
4

4
2
0

Q6: Write a Matlab code to calculate the following summation:


3*(2+1) + 4*(3+2+1) + 5*(4+3+2+1) + 6*(5+4+3+2+1) + .... + 1000*(999 + ... + 1)
Q7: Mr. Rahim just received his April salary which is RM 4000 and he wants to invest in one of the
following bank.
Bank A: 10% interest per year compounded yearly.
Bank B: 1.5% interest per month compounded monthly
Bank C: (10/321)% interest compounded daily.

compounded yearly/montly/daily means that at the end of one year/month/day the interest is
added to Mr. Rahim balance.
Write a Matlab programme where the output will display the total amount of saving that Mr. Rahim
expected to have in each of the bank after he have invest for one year and also display the Bank that
offer the best deal.
Q8: Write a program in a script file that calculates the cost of mailing a package according to the
following price schedule:
Type of Service
Ground

Weight 0 2 kg
RM 1.50 per Kg

Air

RM 3.00

Overnight

RM 11

Weight 2 10 kg
RM 1.50 + RM0.50 for
each kg or fraction of a
kg above 2 kg.
RM 3.00 + RM0.70 for
each kg or fraction of a
kg above 2 kg.
RM 11.00 + RM 2.50 for
each kg or fraction of a
kg above 2 kg.

Weight 10 50 kg
RM 5.00 + RM0.50 for each kg
or fraction of a kg above 10 kg.
RM 7.00 + RM 0.60 for each kg
or fraction of a kg above 10 kg.
No overnight service
packages above 10 kg

for

The program asks the user to enter the weight and the type of service. The program then displays
the cost. If a weight larger that 50 kg is entered for ground or air services, a message Ground (or
Air) services is not available for packages that weight more that 50 kg is displayed. If a weight larger
than 10 kg is entered for overnight services a message Overnight service is not available for
package that weight more than 10 kg is displayed.

Anda mungkin juga menyukai