You are on page 1of 4

EUROPEAN UNIVERSITY OF LEFKE

FACULTY OF ECONOMICS AND ADMINISTRATIVE SCIENCES


CIS 106 INTRODUCTION TO MATLAB SPRING 10-11 FINAL EXAM
Date: 01. 06. 2011 Instructor: Prof. Dr. Hüseyin Oğuz
Place: A-1
Time: 09:30-11:00 (90 min)
Student Registration No:___________________
Student Name-Surname:__________________________________
Important Note: Calculator can be used if it is required (no cellular phone usage).
1. (25 p) Write a program that accepts a numerical value x from 0 to 100 as input and computes and
displays the corresponding letter grade given by the following table:

  90 80    89 70    79 60    69  60
A B C D F
(a) Use nested if statements in your program (do not use elseif )

(b) Use only elseif clauses in your program.

2. (25 p) The position x as a function of time of a particle that moves along a straight line is given by:
 
 0.1  0.8  10  70 

The velocity   of the particle is determined by the derivative of   with respect to , and the
acceleration   is determined by the derivative of   with respect to  .

Derive the expressions for the velocity and acceleration of the particle, and make plots of the position,
velocity, and the acceleration as a function of time for 0   8 . Use the subplot command to
make the three plots on the same page with the plot of position on the top, the velocity in the middle,
and the acceleration at the bottom. Label the axes appropriately with the correct units.

3. (25 p) Engineers usually measure angles in degrees, yet most computer programs and many
calculators require that the input to trigonometric functions be in radians. Write a function DR that
changes degrees to radians and another function RD that changes radians to degrees. Your functions
should be able to accept both scalar and matrix input.

4. (25 p) Aluminium alloys are made by adding other elements to aluminium to improve its properties,
such as hardness or tensile strength. The following table shows the composition of five commonly
used alloys, which are known by their alloy numbers (2024, 6061, and so on) [Kutz, 1999]. Obtain a
matrix algorithm to compute the amounts of raw materials needed to produce a given amount of each
alloy. Use MATLAB to determine how much raw material of each type is needed to produce 1000
tons of each alloy.

Composition of aluminium alloys


Alloy % Cu % Mg % Mn % Si % Zn
2024 4.4 1.5 0.6 0 0
6061 0 1 0 0.6 0
7005 0 1.4 0 0 4.5
7075 1.6 2.5 0 0 5.6
356.0 0 0.3 0 7 0

CIS 106 Final Exam_01-06-11 Prof.Dr. Hüseyin Oğuz Page 1 of 4


CIS 106 INTRODUCTION TO MATLAB SPRING 10-11 FINAL EXAM SOLUTIONS
(01.06.2011)

1. (25 p)
a) The script file is:

x = input(?'Enter the grade (1 - 100); ')

if x >= 90

grade = 'A'

else

if x >= 80

grade = 'B'

else

if x >= 70

grade = 'C'

else

if x >= 60

grade = 'D'

else

grade = 'F'

end

end

end

end

b) The script file is:

x = input('Enter the grade (1 - 100); ')

if x >= 90

grade = 'A'

elseif x >= 80

grade = 'B'

elseif x >= 70

grade = 'C'

elseif x >= 60

CIS 106 Final Exam_01-06-11 Prof.Dr. Hüseyin Oğuz Page 2 of 4


grade = 'D'

else

grade = 'F'

end

(25 p) Script File:


t=0:0.1:8;
x=-0.1*t.^4+0.8*t.^3+10*t-70;
v=-0.4*t.^3+2.4*t.^2+10;
a=-1.2*t.^2+4.8*t;
subplot(3,1,1)
plot(t,x)
xlabel('Time (s)')
ylabel('Position (m)')
subplot(3,1,2)
plot(t,v)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
subplot(3,1,3)
plot(t,a)
xlabel('Time (s)')
ylabel('Acceleration (m/s^2)')

3. (25 p)
% Define a vector of degree values
degrees = 0:15:180;
% Call the DR function, and use it to find radians
radians = DR(degrees);
% Create a table to use in the output
degrees_radians = [degrees; radians]’
% Define a vector of radian values
radians = 0:pi/12:pi;
% Call the RD function, and use it to find degrees
degrees = RD(radians);
radians_degrees = [radians; degrees]’
% The functions called by the program
function output = DR(x)
% This function changes degrees to radians
output = x*pi/180;
function output = RD(x)
% This function changes radians to degrees
output = x*180/pi;

4. The amount of copper (Cu) needed to produce 1000 tons of each alloy is obtained by
multiplying the Cu column in the table by 1000(0.01) = 10. (The 0.01 is neeed to convert
the table’s percents into decimal values.) Thus we need 1000(0.01)(4.4+0+0+1.6+0) =
60 tons of copper. Extending this method, we can see that we must multiply the matrix
composition obtained from the table by a row vector consisting of five columns containing

CIS 106 Final Exam_01-06-11 Prof.Dr. Hüseyin Oğuz Page 3 of 4


the value 10. The session is as follows:

>>composition = [4.4,1.5,.6,0,0;0,1,0,.6,0;0,1.4,0,0,4.5;1.6,2.5,0,0,5.6;0,.3,0,7,0];
>>alloy = 10*ones(1,5)
alloy =
10 10 10 10 10
raw_material = alloy*composition
raw_material =
60.0000 67.0000 6.0000 76.0000 101.0000
Thus we need 60 tons of copper, 67 tons of magnesium, 6 tons of manganese, 76 tons of
silicon, and 101 tons of zinc.

CIS 106 Final Exam_01-06-11 Prof.Dr. Hüseyin Oğuz Page 4 of 4

You might also like