Professional Documents
Culture Documents
Creating detailed plots are extremely useful in many areas of science. Matlab is
known for its ability to produce many types of plots. The main goal of this lab is
to allow you the opportunity to try some of these Matlab capabilities in producing
2D plots.
Reading and related topics: Lecture slides (Lesson #6) and chapters 5 of Amos
Gilat’s book.
Use Matlab to solve the following four problems. Save the code you wrote to solve
them, together with the result of it in a report. Make sure you include enough
comments in your code. Save your report in MLX or PDF format.
Problem 1:
Plot the function shown below and its derivative for 0 ≤ x ≤ 10 in one figure. Plot
the function with a solid line, and the derivative with a dashed line. Add a legend
CPS118 > Lab 05 > Plotting in MATLAB 2
Problem 2:
The shape of the heart shown in the figure below is given by the equation:
where x takes values in the range of -1 to 1.
Create the same plot, noting that the range of x and y should be -1.5 to 1.5 for the
x-axis, and -1.5 to 2 for the y-axis.
Hint: Solve for y in terms of x in order to generate your plot. Note that to generate
this plot, you need to plot two sets of y, given that a square root has ± values.
CPS118 > Lab 05 > Plotting in MATLAB 3
CPS118 > Lab 05 > Plotting in MATLAB 4
Problem 3:
The height and speed of a projectile shoot at a speed v0 at an angle θ as a function
of time are given by:
2
ℎ(𝑡) = 𝑣0𝑡 𝑠𝑖𝑛 θ − 𝑔𝑡 / 2
2 2 2
𝑣(𝑡) = 𝑣0 − 2𝑣0 𝑔𝑡 𝑠𝑖𝑛 θ + 𝑔 𝑡
where g = 9.81 m/s2. Determine the time that the projectile will hit the ground
and plot the height and the speed as a function of time (two plots on one page) for
the case that v0 = 200 m/s and θ = 70°. Add titles and label the axes.
CPS118 > Lab 05 > Plotting in MATLAB 5
Problem 4:
According to Planck's law of black-body radiation, the spectral energy density R as
a function of wavelength λ (in metres) and temperature T (in degrees Kelvin) is
given by:
2
2π𝑐 ℎ 1
𝑅 = 5 × ℎ𝑐 / λ𝐾𝑇
λ 𝑒 −1
where c = 3 × 108 m/s is the speed of light, h = 6.626 × 10-34 J-s is the Planck
constant, and k = 1.38 × 10-23 J/K is Boltzmann constant. Make the figure (shown
below) that contains plots of R as a function of λ for values between 0.1 and 3
μm for three temperatures T = 3000 °K, T = 4000 °K, and T = 5000 °K. Show
everything on the same figure. Use colours, label the axes and add a legend.
CPS118 > Lab 05 > Plotting in MATLAB 6
CPS118 > Lab 05 > Plotting in MATLAB 7
Mock Test:
CPS118 > Lab 05 > Plotting in MATLAB 8
During the last half hour of this lab session, you will get acquainted with the test
environment with a mock test. The computer will be rebooted into the
proprietary online exam system. Follow your lab TA instructions. You will see the
test details from the link below in the exam environment.
Lab05_Practice_Test
Have fun!