Professional Documents
Culture Documents
Homologation
Extra exercises (2015)
By: Bouke Haarsma
This document contains extra exercises for the Matlab-basics homologation module. These exercises
will be harder compared to the module offered on oncourse. (http://oncourse.tue.nl).
Please use these questions as confirmation you understand the material, so solve these exercises
individually! It is also recommended to use the mathworks documentation
(http://mathworks.com/help) and matlab help command, before asking for help or copying code
from Google. By doing so, you will be better prepared when help is not easily available.
Good luck!
Bouke
Exercises
1. Starting
a)
25
25 1
5 1
1
b. 3
( 5 + 1) 2
a.
b)
c)
a.
d)
e)
f)
b. 3
3. Going diagonal
Create the following matrices using one line in the command window without defining the matrix
element wise. (Use the Matlab help!):
0 0 0
a) = 0 0 0
0 0 0
1 1 1
b) = 1 1 1
1 1 1
1 0 0
c) = 0 1 0
0 0 1
1 0 0
d) = 0 2 0
0 0 3
2 0 0
e) = 2 2 0
2 2 2
f)
0 4 4
= 2 1 4
2 2 2
a) Create a script called Ex1. Since a full circle will be drawn, this means angle is between 0
and 2 radians. So in the script, create a vector called theta containing all numbers between
0 and 2 with a step size of 1 .
b) Run the script. Verify if a) has 6 elements. Why should it have 6 elements? Why does the
vector end at 6 and not at 2?
c) The circle will have a certain radius. Call this radius R. Edit the script. Using a) and R how can
x and y vectors for this circle be obtained? For now, use R=5.
Hint: what are the equations for x and y?
d) Edit the script so the circle is plotted, is the result as expected? What can be done to
improve the results?
e) Create a new function called circ. The input for this function is R and the outputs of the
function the X and Y (these variables will be vectors). Use a) and c) for the proper equations.
f)
In the command window, use the circ function. (e.g. circ(5) ). By using only the command
window and the circ function, create X and Y values in the workspace and plot the results.
Hint: this will take 2 commands.
g) Edit the script created previously so it uses the function circ instead of manually creating the
X and Y vectors.
h) Using the Mathworks help page: what is the command for retaining multiple plots in a single
window? Also see the examples given on the page to get an idea on how to use the
command.
i)
Using the answer from g) and the circ function created. Change the script created that plots
2 circles with different radius in a single window.
5. Got it!
Matlab is very fast in many equations at once due to the usage of matrices and vectors. In this
exercise this set of equations will be solved using Matlab:
2 + 10 + 11 = 327
6 + + 11 = 286
14 + 13 + 6 = 229
12 + 14 + 10 = 332
14 + 10 + 3 = 139
&' = (
With & as matrix and ( and ' as vectors. Whereas the vector ' is equal to )*.
a) Insert the matrix & and vector ( in Matlab. What should the sizes of these variables be?
One way to solve this is retrieving the row reduced echelon form of the matrix .
b) What is the command for retrieving this form in Matlab? Use the mathworks help.
c) Use the command on the matrix [& (]. What are the answers for , and ?
d) Verify these results by constructing the vector ' and calculating the vector (. Should the *
or the .* command be used? Why?
A other way to solve this set of equations is by using the mldivide command
e) The mldivide has a shorter notation. What is this notation?
f) Solve the equations using the mldivide command.
Matlab has a lot of commands to solve this set of equations.
g) Search the help for mldivide for another command to solve this system.