0% found this document useful (0 votes)
16 views2 pages

Function Quiz1 This Is Quiz Question 1 X Zeros (1,10) For I 1:10 X (I) I End y X 2/2+2x Plot (Y, X)

This document contains a 3 question quiz on Matlab programming with the following details: 1) Question 1 (20 marks) asks to identify and correct 5 syntax errors in a provided Matlab program that is meant to plot a graph but contains errors. 2) Question 2 (20 marks) provides a Matlab program and asks for the output given two different inputs. 3) Question 3 (30 marks) asks to write a Matlab program that takes a positive integer as input and outputs an n x n matrix containing the first n elements of the Fibonacci sequence in a specified order.

Uploaded by

peilin93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Function Quiz1 This Is Quiz Question 1 X Zeros (1,10) For I 1:10 X (I) I End y X 2/2+2x Plot (Y, X)

This document contains a 3 question quiz on Matlab programming with the following details: 1) Question 1 (20 marks) asks to identify and correct 5 syntax errors in a provided Matlab program that is meant to plot a graph but contains errors. 2) Question 2 (20 marks) provides a Matlab program and asks for the output given two different inputs. 3) Question 3 (30 marks) asks to write a Matlab program that takes a positive integer as input and outputs an n x n matrix containing the first n elements of the Fibonacci sequence in a specified order.

Uploaded by

peilin93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name:

AY2010/2011

CH1011 Introduction to Programming Quiz (Open Book, Time: 1 h)


This quiz contains a total of 2 pages and 3 questions. Answer all questions. Write your answers
on the question paper. No calculators and electronic devices are allowed.
Total marks = 70.
1. The following Matlab program quiz1 is to plot a graph of y versus x where y
x 0,1,2,...,8,9.

x2
2 x for
2

Identify and correct the 5 syntax and/or logical errors in the program.
(20 marks)

function quiz1
This is quiz question 1
x=zeros(1,10)
for i=1:10
x(i)=i;
end
y=x^2/2+2x;
plot(y,x)
2. Consider the following Matlab program quiz2:
function quiz2(a,b)
if b>a
disp('A')
elseif b<a
disp('B')
if b==a
disp('C')
else
disp('D')
end
end
Write down the output for each of the following inputs:
(a)

(b)
(20 marks)

Please turn over


1

Name:

AY2010/2011

3. The Fibonacci sequence is given as:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,


where a1 = 0, a2 = 1, and the nth number an is given by:
an an 1 an 2

n 3,4,5...

Write a Matlab program so that it will


(a) take as input a positive non-zero integer n 2,
(b) produce as output an n x n square matrix whose elements are the first n x n numbers of the
Fibonacci sequence in the following order:
(i) row 1, going from column 1 to column n,
(ii) row 2, going from column 1 to column n, etc till row n.
You may assume that the user will always input a positive non-zero integer 2.
You may use any Matlab built-in functions.
(30 marks)
Examples:

--- End of paper --2

You might also like