You are on page 1of 2

Modeling and Simulation: problem sheet 2 1

Theoretische Elektrotechnik
Universität Paderborn

Matlab Fundamentals, Modeling on Real Physical Problems


return: 23.10.2022 23:59 (20 points)

Create a matlab script file (m-file) for the following problems:

1. Use
 “diag” function
 to generate the matrix (1P):
6 −4 −2 9
 7 6 −4 −2 
 
 1 7 6 −4 
3 1 7 6

2. Logical Operators (2P):

(a) Define a 1 × 6 vector A with elements equal to (3, 1, 5, −4, 2, 8) and a 1 × 6 vector B with
elements equal to (7, 1, 0, 2, 3, last digit of your matriculation number). (0P)
(b) Compare the corresponding values of A and B element-wise using “Less than”, “Greater
than”, “Equal to”, and “Inequal to”. Return the result to vector C. Write out the
resulting vectors as a comment (%...).(1P)
(c) Use logical operator “AND” to check element-wise if each element of a vector A and
corresponding element of a vector B is simultaneously greater than last digit of your
matriculation number. Return the result to vector C. Write out the resulting vectors as
a comment. Do the same using operator “OR”. (1P)

3. Flow Control (3P):

(a) Define a 4 × 4 matrix M obtained by the element-wise multiplication of the matrix given
in problem 1 with last digit of your matriculation number (if it is zero use the next last
digit). (0P)
(b) Use “for” loop to find the minimum number in M . Write out the resulting value as a
comment. (1P)
(c) Use “while” statement to find the maximum number in M . Write out the resulting value
as a comment. (1P)
(d) Calculate the summation N k
P
i=1 i for k = 1, 2, 3 and N =last digit of your matriculation
number (if it is zero use the next last digit). Write out the obtained results. (1P)

4. Functions and Data Plotting Tools (10P):

(a) Write your own MATLAB function which solves quadratic equation ax2 + bx + c = 0.
Input parameters are a,b, and c, and output parameters are equation’s roots. In the
main MATLAB script, call your function and find the roots of this quadratic equation for
the values of a = 2, b = 3, c =last digit of your matriculation number and write out the
solution. Compare your solution with results from the MATLAB function “root”. (5P)
(b) Write your own MATLAB function which converts spherical coordinates to cartesian co-
ordinates. Three input parameters are r, θ, ϕ, where r is always a constant (scalar), and
θ and ϕ could be constants (scalars) or one dimensional arrays. Three output parameters
could be scalars or one dimensional arrays of corresponding cartesian data x, y, z. In the
main MATLAB script, call your function with r =last digit of your matriculation number
(if it is zero use the next last digit), θ and ϕ are randomly generated data of size 1000∗last
Modeling and Simulation: problem sheet 2 2

digit of your matriculation number using MATLAB function “rand” in the range 0 − π
and 0 − 2π, respectively. Plot the data using “plot3” function with options ’LineStyle’ -
’none’ and ’Marker’ - ’o’. Add mesh grid, axis labels, title, and legends on the figure.(5P)

5. Modeling on Real Physical Problems (4P): For all classifications mentioned in the lec-
ture ((1) physical, (2) abstract (paper, computer etc), (3) static, (4) dynamic, (5) real-time,
(6) interactive, (7) (time-) continuous, (8) discrete (iterative or event driven), (9) realistic, (10)
simplistic, (11) natural, (12) artificial, (13) imagined system, (14) simple, (15) complex, (16)
deterministic, (17) stochastic, (18) known input, (19) statistical properties of input known,
(20) unknown input), think of one model which falls into that category. Models may reappear,
but should be clear and specific.
Example: “pendulum from lecture: 2,4,7,10 (damping neglected), 11, 14, 16, 18”.

Instructions for the Submission:

For homework submission, make sure that you submit three m-files:

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

2. Two m-files - functions of Exs. 4a and 4b with names “ps 2 ex 4a your matriculation number.m”
and “ps 2 ex 4b your matriculation number.m” respectively .

You might also like