ENGG100 Fall2023 Lab02 Slides
ENGG100 Fall2023 Lab02 Slides
Numerical
Plotting
Techniques
• The area plot is quite similar to the simple x-y plot, the only exception
being that the area under the curve is filled in.
• The code area(x, y) results in the area plot.
• The text color changes to red when you enter a single quote ('). This alerts
you that you are starting a string (a list of characters enclosed by single
quotes).
• Select the docking arrow underneath the exit icon in the upper right-hand
corner of the figure window.
ENGG100 – Fall 2023 7
Creating Multiple Plots
• Execute the following commands: • Use sections to execute your
x = 0:pi/100:2*pi; program interactively, one section
y1 = cos(x*4); at a time - ensuring each section
generates no more than one figure.
plot(x,y1)
y2 = sin(x); • Run your entire program using the
pause command to temporarily
figure y2)
plot(x, halt the execution so that you can
plot(x, y2) examine the figure.
• Create multiple figure windows
using the figure function.
• The indicators are listed inside a string, denoted with single quotes. The
order in which they are entered is arbitrary and does not affect the output.
x=012345 11
y = 15 10 9 6 2 0 9
y-axis
7
• Polynomial regression is used to get the best fit by minimizing the sum of
the squares of the deviations of the calculated values from the data.
• The polyval function requires two inputs: the first is a coefficient array and
the second is an array of x-values for which we would like to calculate new
y-values.
The Polyval Function
clear subplot(1,3,1)
x = 0:5; y = [15, 10, 9, 6, 2, 0]; plot(x,y,'o', x_smooth,y3)
x_smooth = 0:0.1:5; axis([0,6,−5,15])
f1 = polyfit (x, y, 1) subplot(1,3,2)
y1 = polyval(f1,x_smooth); plot(x,y,'o', x_smooth,y4)
axis([0,6,−5,15])
y2 = polyval(polyfit (x, y, 2), x_smooth) subplot(1,3,3)
y3 = polyval(polyfit (x, y, 3), x_smooth) plot(x,y,'o', x_smooth,y5)
y4 = polyval(polyfit (x, y, 4), x_smooth) axis([0,6,−5,15])
y5 = polyval(polyfit (x, y, 5), x_smooth)
Let’s Practice