Sei sulla pagina 1di 1

Exercises

Chapter 1 Modelling and Simula8on using MATLAB


Please note, that these exercises will not be graded. You will get sample solu9ons later!

1. Using Help
1.1. Experiment or use help elfun to answer the following ques7ons:
a) What is the dierence between the func7ons mod and rem?
b) For what range of values is the func7on round equivalent to the func7on oor?
c) Is oor( 1.2) the same as x(1.2) ?
d) Is oor(1.5) the same as ceil(1.5) ?

2. Arrays and Matrices


2.1. Create a 4 x 6 matrix of random numbers in the range from 0 to 1. (use the rand func7on)
2.2. Create a 4 x 6 matrix of random numbers in the range from 11 to 111.

3. PloGng
3.1. Plot a sine func7on in the range of 0 to 4pi
3.2. Plot a sine func7on in the range of 0 to 4pi with 501 points in this range.
3.3. Plot a sine func7on in the range of 0 to 4pi with 101 points using the stem command.

4. Scripts and Func8ons


4.1. Write a script that displays hello world in the command window. (use the disp func7on)
4.2. Write a script that will prompt the user for his name and echoes Hello <username>. (use the
func7ons disp and input.)
4.3. Write a script that simulates a dice by using the command randi.
4.4. Write a func7on that receives the radius r as an input argument, and calculates the
circumference c and the area a of a circle with the radius r.
4.5. Write a func7on that receives the radius r as an input argument, and calculates the volume of a
sphere with the radius r.
4.6. Convert the example m-le while_example.m to a func7on that receives an input variable with
the number of digits numdigit instead of calcula7ng n for the xed value 51.
4.7. Play with the example m-le for_example.m. Change the sine func7on to a cosine func7on and
change the range and step size of the index variable k.
4.8. Play with the example m-le randnorm1.m. Change the number of bins in the histogram,
change the value of the standard devia7on, and change the number of pseudorandom values
(help histogram, help randn)
4.9. Change the if and elsif statement in the provided example if_example.m so that it will use the
< sign instead of the > sign.

Potrebbero piacerti anche