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

Modeling and Simulation Ps1

The document provides instructions for a Matlab assignment involving vector and matrix manipulations, data analysis functions, complex numbers, plotting tools, and defining a Matlab function. Students are asked to create an m-file script to demonstrate their skills in these areas and submit both the script file and a separate function file to complete all parts of the assignment. The assignment covers basic Matlab skills and is worth 20 points total.

Uploaded by

Rehman Saleem
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)
60 views2 pages

Modeling and Simulation Ps1

The document provides instructions for a Matlab assignment involving vector and matrix manipulations, data analysis functions, complex numbers, plotting tools, and defining a Matlab function. Students are asked to create an m-file script to demonstrate their skills in these areas and submit both the script file and a separate function file to complete all parts of the assignment. The assignment covers basic Matlab skills and is worth 20 points total.

Uploaded by

Rehman Saleem
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/ 2

Modeling and Simulation: problem sheet 1 1

Theoretische Elektrotechnik
Universität Paderborn

Matlab fundamentals
return: 20.10.2022 13:00 (20 points)

Create a script file (m-file) with the following Matlab commands:

1. Vector and matrix manipulations (7P):

(a) Get help on command “zeros”.


(b) Get help on command “ones”.
(c) Get help on command “rand”.
(d) Define 1 × 5 (1-row and 5-columns) vector a with all elements equal to 0.
(e) Define 3 × 1 (3-rows and 1-column) vector a with all elements equal to 1.
(f) Define 1 × 5 vector a with elements equal to 1, 2, 3, 4, π, correspondingly.
(g) Define 3 × 1 vector a with elements equal to 0.1, 0.2, 0.3, correspondingly.
(h) Define 1-row vector a with the elements’ values from 3 to 27 with step 3 by using operator
“:”.
(i) Define 1-row vector a of 10 linearly equally spaced points between x1 and x2 , where x1
and x2 are the first and last numbers of your student id (use linspace function).
(j) Define 3 × 3 matrix a of random number elements.
 
1 2
(k) Define 3 × 2 matrix a =  3 4 .
5 6
(l) Check the size of the matrix a.
 
1 20 30
(m) Define 3 × 3 matrix a =  40 50 60 .
70 80 90
(n) Transpose the matrix a.
(o) Show (print on display) the element a32 of the transposed matrix a.
(p) Show (print on display) the second row of the transposed matrix a.
(q) Show (print on display) the third column of the transposed matrix a.
   
1 2 3 1 2 3
(r) Define matrix a =  4 5 6  and b =  4 5 6 .
7 8 9 7 8 9
(s) Sum matrices a and b, c = a + b.
(t) Multiply matrices a and b, c = a ∗ b.
(u) Multiply matrices a and b element-by-element, i.e. cij = aij ∗ bij .
(v) Solvethe linear 
system of equations
  ax = b by using inv() function, if
3 1 1 8
a=  1 3 1  and b =  10 .
1 1 3 12
(w) Solve the same system by using operator \.
Modeling and Simulation: problem sheet 1 2

2. Data analysis functions (4P):

(a) Calculate the square root of your student id.


(b) Define the 1-row vector a(11, 7, 32, 34, 13, your student id number).
(c) Get the value of the last element of vector a by using the special “end ” operator.
(d) Get the part of array a starting from 3rd index by using “:“ and “end ” operators.
(e) Find minimum value of the vector a.
(f) Find maximum value of the vector a.
(g) Calculate the mean value of the vector a.
(h) Make summation of elements of the vector a.
(i) Calculate the square roots of all elements of the vector a.
(j) Sort the vector a in the ascending order a.
(k) Find the roots of the polynomial equation x4 + 4x3 − 5x2 + 6x − 9 = 0.

3. Making complex numbers (1P):

(a) Make a complex number a = 2 + 3 ∗ i.


(b) Get the real part of a.
(c) Get the imaginary part of a.
(d) Get the complex conjugate of a.
(e) Get the value of complex number i.

4. Plotting Tools (2P):

(a) Get help on command “plot”.


(b) Plot the graph of y = exp(x), for −2π ⩽ x ⩽ 2π.
(c) Plot the graph of y = log(x), for 0 < x ⩽ 2π.

5. Matlab functions (6P):


Write the matlab function (m-file) that a) creates the square matrix a of the size n × n with
all diagonal elements equal to 3 and all other elementsP
equal to 1 (you may use diag and ones
functions) and vector b of size n with elements bi = nj=1 j ∗ aij , b) solve the linear system
of equations ax = b. The function takes one input parameter - n, and output is the solution
vector - x. Run the code for n equal to last number of your student id, if this number is equal
to 0 or 1 use the number 9, etc. Copy the obtained values of the vector x at the end of this
m-file.

Instructions for the submission:


For homework submission, make sure that you submit two m-files as per following detail:

1. One script m-file of Exs. 1-5 with the name “ps 1 ex 1-5 your matriculation number.m”.

2. One function m-file of Ex. 5 with the name “ps 1 ex 5 your matriculation number.m”.

You might also like