Scientific Calculations and MATLAB (CSCT5107)

Computer Science - COS

Semester: First Semester

Level: 500

Year: 2019

1/2
FIRST SEMESTER EXAMINATION
SCHOOL: H.T.T.T.C DEPARTMENT: COMPUTER SCIENCE
OPTION: FCS500 COURSE CODE: CSCT5107
COURSE TITLE: Scientific calculations and MATLAB CREDIT VALUE: 3
DATE: March 2019 DURATION: 1:30 START TIME………END TIME……………
LECTURER: Mr. DJAMEN NYONKEU Gildas
Instruction: Answer all questions.
Q 1) (1x3+2+2=7pts)
a) Differentiate between assembler language, machine language and high level language
b) Differentiate between compiler language and interpreted language
c) Differentiate between scripts and functions
Q 2) (3+1.25x4+1x2+1+3)
1. What are 3 types of errors found in MATLAB programs? (with an example)
2. Evaluate the following Logical Boolean expressions:
a) i=5; j=23.2;
P=(i > 10) && (j > 0)
b) x=2; y=3; i=2;
Q=((x + y) <= 15) || (i <= 5)
c) i=5; j=23.2;
R=~((i >= 10) || (j <= 24))
e) a=10; b=0;
T=xor(a==b,b>0) (2.5 marks)
3. Assume that array A is defined as shown, and determine the contents of the following sub-arrays:
A=[1 2 3; 4 5 6; 7 8 9; 1 2 3];
B=A(:,1)
C=A(2:3,:) (1 mark)
4. What would be the exact output displayed when the following script is run in the MATLAB
environment?
x=21.0256;
fprintf('x equals %5.3f. \n', x) (1 mark)
5. The following MATLAB statements are used to create the plot of the function f(t) given by:
where the values of t vary between -9 and 9 with, a step size of 0.5.
Fix the errors in the following MATLAB code.
clc ;clear ;close;
t=-9:9:0.5;
for i=1:length(t)
if t>=0
f(i)=-exp^t+5;
else
f=3t^2+5;
end
plot(t,f)
REPUBLIC OF CAMEROON
Peace Work Fatherland
THE UNIVERSITY OF BAMENDA
P.O. BOX BAMBILI
www.schoolfaqs.net
2/2
xlabel(x)
ylabel(y)
Q 3) (7+7=14pts)
a) Perfect numbers are numbers that are the sum of their factors. For example 6 is a perfect number
, as its factors are 1,2 and 3 and 1+2+3=6
Abundant numbers are numbers that are less than the sum of their factor. For example, 12 is an
abundant number, as its factors are 1,2,3,4 and 6 and 1+2+3+4+6=16 which is greater than 12
Deficient numbers are numbers that are greater that the sum of their factors. For example 10 is
deficient as it is the factors are 1,2, and 5, and 1+2+5=8 which is less than 10
Write a matlab function that determines if a number is perfect, abundant, or deficient. Do this by
finding the factors of the input number, then the sum of the factors, then compare the sum with the
input number, In build matlab function you may need include rem() and sum()
b) Using the function you wrote for the question above, write a program to find how many perfect,
abundant and deficient numbers there are below 10,000. Print the result in a formatted manner.
Q 4) (7+7+7+7+7=35 pts)
1. Determine the LU factorization of the matrix
A=[
1 2 3
4 5 6
7 8 9
]
2. Solve Ax = b, where A is the matrix in 1 and b = [10,11,12]
T
, by using the LU factorization
3. Write a MATLAB function for computing the LU factorization of a general n×n matrix. The
function call should look like function [L,U]=lufactors(A)
Test the code on a few examples.
4. Write a MATLAB function for the solution of the lower triangular system (4) by forward
substitution. The function call should look like function [y]=forwardsubst(L,b)
Test the code on a few examples.
5. Write a MATLAB function for the solution of the upper triangular system (5) by back
substitution. The function call should look like function [x]=backsubst(U,y)
Test the code on a few examples.
“A good presentation of the paper is advisable”
www.schoolfaqs.net