01:198:107 Lecture Notes - Lecture 17: Farad
CS 107: Lecture 17: Two Dimensional Plots
● 2-D plot command
○ plot (x,y)
■ Where x is a vector(one dimensional array), and y is a vector. Both
vectors must have the same number of elements
○ The plot command creates a single curve with the x values on the
horizontal axis and the y values on the vertical axis
○ The curve is made from the segments of lines that connect the points that
are defined by the x and y coordinates of the elements in the two vectors
● Creating the x and y vectors
○ If data is given, the information is entered as the elements of the vectors x
and y
○ If the values of y are determined by a function from the values of x, then a
vector x is created first, and then the values of y are calculated for each
value of x
○ The spacing between the elements of x must be such that the plotted
curve will show the details of the function
● Line specifiers in the plot
○ Specify the style of the line
○ Specify the color of the line
○ Specify the type of the markers
○ plot(x,y,’line specifiers’)
○ Within the string the specifiers can be typed in any order
○ The specifiers are optional
● Creating a plot of a function
○ If the vector x is created with large spacing, the graph is not accurate
● The fplot command
○ The fplot command can be used to plot a function with the form: y=f(x)
○ fplot=(‘function’, limits)
○ The function is typed in as a string
Document Summary
Where x is a vector(one dimensional array), and y is a vector. Both vectors must have the same number of elements. The plot command creates a single curve with the x values on the horizontal axis and the y values on the vertical axis. The curve is made from the segments of lines that connect the points that are defined by the x and y coordinates of the elements in the two vectors. If data is given, the information is entered as the elements of the vectors x and y. If the values of y are determined by a function from the values of x, then a vector x is created first, and then the values of y are calculated for each value of x. The spacing between the elements of x must be such that the plotted curve will show the details of the function. Within the string the specifiers can be typed in any order.