0% found this document useful (0 votes)
22 views

EECS1560 test 1_Sample (1)

This document is a sample practice test for EECS 1541 at York University, covering MATLAB programming concepts and problem-solving. It includes instructions, sample problems, and questions related to MATLAB syntax, matrix operations, and function writing. The test is designed to help students prepare for their formal examination by providing similar questions and guidelines for answering them.

Uploaded by

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

EECS1560 test 1_Sample (1)

This document is a sample practice test for EECS 1541 at York University, covering MATLAB programming concepts and problem-solving. It includes instructions, sample problems, and questions related to MATLAB syntax, matrix operations, and function writing. The test is designed to help students prepare for their formal examination by providing similar questions and guidelines for answering them.

Uploaded by

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

Name:____________________________ Student #:______________________

York University
Department of Electrical Engineering & Computer Science

Lassonde School of Engineering

EECS 1541: Introduction to Computing for Mathematics and Statistic


Test 1 (Sample)

Instructor: Mehdi Abbasi


This practice test 1 gives sample practice problems for the Fall 2022 Test 1 of EECS 1560. They
DO NOT cover the full extent of the material you need to know but they will be similar to the
questions on the formal examination. They do not resemble the number of problems or
problem distribution along topics in the test. The time it takes to solve the problem can differ
from the real exam.

Instructions:

 Print your name and student ID# at the top of each other page.
 Show your work to receive maximum credit. Partial credit will be given, but only if work is
shown.
 If we cannot read your hand writing, we cannot give you credit.
 Circle, mark, or otherwise indicate your answer to each question.
 Please keep your written answers brief and to the point. Incorrect or rambling statements
can hurt your score on a question.
 If the question requires you to provide code, you must use correct MATLAB syntax and
semantics to receive full credit. We should be able to type your answer into MATLAB and
verify that it works.
 No calculator, electronic devices, books, notes, or cheat sheets are allowed in the test

Total: 40
1
Name:____________________________ Student #:______________________

1. Determine the output for each of the following MATLAB instructions: [10]

a) round(-3.1) [1]

b) 18 && (100 - 45 == 45 * ~(12 + 8 > 20)) [1]

c) x = 10:-2:3; [2]
x(3) = [];
find(x(rem(x,4)==0))

d) n = 3; [2]
vec = n:2^n;
vec(vec > n+1)

e) fprintf('The area when r = %.fcm is: %4.2fmm^2\n',3,567.01234)

[2]

2
Name:____________________________ Student #:______________________

f) mat = [1:3; zeros(2,3)]; [2]


a= length(mat-1)
mat(:,5)=3:-1:1;
b= numel(mat)

2. Answer the following questions: [8]

a) Write two ways to display the following matrix: [2]

3 4 5 6 7
A   
13 14 15 16 17 

b) What is the difference between clc and clear commands? [1]

c) Choose the correct answer choice that, when replacing the blank below, produces the values for
the variable named result shown below. Hint: note that result displays the x values that
correspond to the smallest value in y. [1]

>> y = [-7, 2, 5,-1,-7, 0, 4, 0,-7, 1];


>> x = [0.8, 0.2, 0.3, 0.4, 1.3, 0.6, 0.5, 0.8, 0.9, 1.0];
>> result =……………………………

result = 0.8000 1.3000 0.9000

(a) y(x == min(x))


(b) x(y == min(y))
(c) y(min(x))
(d) x(min(y))

3
Name:____________________________ Student #:______________________

d) You wish to write a function that will plot the following function: [4]

y  0.5 sin(et ) cos(t 2 )  1 for 0 ≤ t ≤ 2π

Write a m-file for the function that is named fcn1.m. Choose a proper time-step. Include the labels.

3. Consider a 4 x 3 matrix A: [8]

 10 1 9 18 
 
A 6 2 0 8 
 3 24 12 4 
 

a) Determine the output for each of the following 2 cases. Explain each case. [4]

I. A(:,1)*A(:,2)

II. A(:,1).*A(:,1)

b) Using a single MATLAB statement, show how to interchange the first and third columns
in A. [2]

c) Using a single MATLAB statement, show how to determine the total number of integers
that are divisible by 4 in A. [2]

4
Name:____________________________ Student #:______________________

4. Write the screen display in the command window in the space provided for the following script
and associated functions. Show all the steps. Credit only given for work shown. [5]

% script

clc; clear;
x = 5
y = 2
z = [0 6 5 3 1];
for i = 1:2:5
if (i <= 2)
back1 = fcn1(i,x,y,z)
Display Display
elseif (i > 3)
#
disp('done')
else 1
back2 = fcn2(i,y,x,z)
end 2
end
3

function [out2] = fcn1(j,y,x,k) 4


out2 = zeros(1,4)
for i=1:3:5 5
out2(i) = fcn2(i,x,y,k);
end 6
end
7
function [out1] = fcn2(j,d,s,k)
switch (k(j)) 8
case {1,2}
out1 = d+9 9
case {3,4}
out1 = 2*s 10
otherwise
11
out1 = d+s
end 12
end

5
Name:____________________________ Student #:______________________

5. Write a script that will print the following multiplication table: [3]

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25

6. Write a function called “vec2sqr” that will receive two row vectors (v1 and v2) as input arguments,
and from them create and return a square matrix in which the first two rows are v1 and v2 and the rest
are zeros. You may not assume that the length of the vectors is known. An error message will be
displayed in the command window if the length of v1 and v2 are different.
[6]
Example 1
>> v1=[1 2 3 4];
>> v2=[5 6 7 8];
>> vec2mat(v1,v2)

ans =

1 2 3 4
5 6 7 8
0 0 0 0
0 0 0 0

Example 2

>> v1=[1 2 3];


>> v2=[5 6 7 8];
>> vec2mat(v1,v2)
Error, the length of the vectors are different

6
Name:____________________________ Student #:______________________

List of MATLAB built-in functions

abs()
atan()
axis()
ceil()
cos()
cosd()
disp()
exp()
find()
fix()
floor()
fprintf()
grid
inv()
inf
legend()
length()
linspace()
log()
log10()
max()
min()
mod()
norm()
ones()
pi
plot()
prod()
rand
randi()
rem()
round()
rref()
sin()
sind()
size()
sqrt()
sum()
tan()
tand()
title()
xlabel()
ylabel()
zeros()

You might also like