Y 5 X +2 X Y: Values Ranging From

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

LAB 2

In this class we are going to look at 2D plots, mainly linear and Quadratic graphs.

To plot the function y=5 x +2on the interval [−1; 1] we first create a vector of x values ranging from
−1 to 1, then compute the y values, and finally plot the result:

1. Linear graph MATLAB 2016 Coding:


x = -1:0.01:1;
y = 5*x+2;
plot(x,y)
Notes:
 -1:0.01:1 yields a vector that
o starts at −1,
o takes steps (or increments) of 0.01,
o stops when 1 is reached.
 If you omit the increment, MATLAB automatically increments by 1.

MATLAB enables you to add axis labels and titles. For example, using the graph from the previous
example, add an x and y -axis labels.
Now label the axes and add a title as shown below:

xlabel('x')
ylabel('y')
title('Plot of y=5x+2')

2D plot for the above example is:


Plot of y=5x+2
7

2
y

-1

-2

-3
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
x
Exercise: Use MATLAB to plot y=x 2 +5 x+ 4 on the interval [−10:5 ] and add axis labels and titles.

You might also like