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

Exercise New

Uploaded by

646475468
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)
16 views4 pages

Exercise New

Uploaded by

646475468
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/ 4

Exercise 1.

l Calculate the following terms with MATLAB:


!·#$%
Ø &! $'

Ø 𝑒 ()*&.,
"#
-./01
$.&·(.#
Ø
2

l Do the following calculations with MATLAB:


3 5 1
Ø A = & 2 0 1-
−1 1 0
Ø 𝐵 = (−2, 1, −4)3
Ø 𝐶 = 𝐴$' 𝐵

l Create a sequence from −3 to 5 with step width 0.1

l Create a sequence from 10 −3 to 10 5with increments on a logarithmic scale, i.e. the


resulting sequence should contain the numbers 10−3, 10−2, 10−1, 100, 101, 102, 103, 104,
105. Thereto, combine sequence generation with the (element-wise) power function.
Write down the MATLAB commands.

l calculate the following term: ∑'44


56' 𝑘 · (101 − 𝑘). Thereto, create an increasing
sequence 𝑢:⃑ and a decreasing sequence 𝑣⃑ and calculate 𝑢:⃑ · 𝑣⃑ T. Write down the
MATLAB commands and the result.

l Create a 5*6 random two-dimensional array A, and use the logical 1 identifier to find all
elements in A that are greater than 0.3 and less than 0.7, and assign them to B.

l Create a 4*4 two-dimensional array A with all values 0 an a 4*3 two-dimensional array B
with all values 1. Splice A and B into a 4*7 two-dimensional array.

3 2 0
l A = &−5 6 1-
1 0 2
Ø Use the “find” function to find the linear index of the non-zero elements of the A
matrix.
Ø Find the subscripts of the rows and columns in matrix A with element 0.
Ø Find the official documentation and learn more about the use of the “find” function.
1 25 7 20
8 90 30 18
l A = > B
12 23 15 176
50 0 31 9
Ø Add a fifth column and assign the values [1, 0, 2, 8] in matrix A.
Ø Sum of the number of rows and columns of matrix A.
Ø Assign the elements of columns 1, 3 and 5 of rows 2-4 of matrix A to matrix B.
Ø Assign A to matrix C, delete the first and third rows of C and display them.
Ø Rearrange matrix A into a matrix of 5 rows and 4 columns.
Ø Find the mean value for each column of matrix A.
Ø Find the mean value for each row of matrix A.
Ø Calculate the mean value of all elements in matrix A.
Ø Assign the first and last values of matrix A to nan.
Ø Calculate the mean of all element in matrix A, excluding nan.
Exercise 2.

l plot sin(20x) ·exp(-x) in the interval [0,5] using solid line, then plot ±exp(-x) on the same
graph using dashed line; add descriptions and change default font to Times New Roman
and font size to 15.

Exercise 3.
l Write a function in MATLAB that calculates the Euclidean distance between two vectors
,
u and v: C∑)(𝑢) − 𝑣) )

Exercise 4.
l plot contour for D((𝑥 − 0.5), + (𝑦 − 0.5), ) ∙ ((𝑥 + 0.5), + (𝑦 + 0.5), ) in the interval
[-0.8,0.8] × [-0.8,0.8] using blue line, then denote both minima using red cross; add axis
description and a title.

Exercise 5.

l Implement simple database storing people names and ages. Database should be stored in
a .mat file and accessed through a function ‘people.m’ that can work in four modes as
illustrated below (here, db_file is a string storing the database file name)

Ø people(db_file,’reset’) – erases the database

Ø people(db_file,’list’) – displays the database content (list of people)

Ø people(db_file,’insert’,’John’,25,’Anna’,17) – inserts new items

Ø people(db_file,’remove’,’Jack’,15) – removes items from database

l Test your database using a sequence of commands below. The preferred format for storing
data is a structure. Please use a given list to start.

Ø Add [your name, your age] to the list; Display the list

Ø Remove [“Tom”] from the list; Display the list

Ø Add [“Joe”,24; “Ella”,28] to the list; Display the list

Ø Reset the list; Display the list


Exercise 6.
l Implement Matlab function that draws a polygon defined by its vertices and rotates it with
respect to the center of the coordinate system as shown below. The angle of rotation should
be determined by the user.

Test your code using a given example. Rotating clockwise and rotation angle is calculated
using the following formula: mod([Your ID number],360).

Exercise 7.
l Given N × N rectangular grid, mark certain number of randomly selected nodes as
obstacles. Develop and implement an algorithm that searches for the (possibly shortest)
path from the bottom edge of the grid to its top edge assuming that possible moves are
only vertical or horizontal. The path must not pass through an obstacle. Visualize the grid,
obstacles and the path similarly as shown below. Test your code for various cases
(different value of N, different density of obstacles). Please use the given obstacle maps.

You might also like