clear; close all; clc; format shortg; %This chapter is all about plotting %Three main commands, plot(), fplot(), and polar() %plot: %plots the points of vectors and connects the dots x1 = [0:5]; y1 = 2*x1; y2 = 3*x1; plot(x1,y1,'--rd'); %Plots our function as a dashed red line %with the points marked as diamonds %Play around with the options found on page 136-137 %You can use plot to plot two functions. figure; %Opens a new figure window plot(x1,y1,x1,y2); %Be careful with how close your points are x3 = [0:2*pi]; y3 = sin(x3); x4 = [0:.1:2*pi]; y4 = sin(x4); figure; plot(x3,y3,x4,y4); %Sometimes you'll want to plot one function in different pieces %For example if you have an asymptote %How to plot multiple functions on one graph %2 ways, plot command and hold on ... hold off x5 = [-2:.01:-1.01]; x6 = [-.99:.01:1]; %notice I avoid x = -1 y5 = 1./(1+x5); y6 = 1./(1+x6); %the asymptote figure; plot(x5,y5,x6,y6,'b'); %each new funtion will have a different color %unless you tell it otherwise axis([-2 1 -10 10]); %defines my domain and range on the graph figure plot(x5,y5) axis([-2 1 -10 10]) hold on plot(x6,y6) hold off %tells matlab that I want to add to my graph %tells matlab I'm done adding to my graph %fplot %fplot, plots functions figure; fplot('sin(x)',[0 2*pi -2 2],'--g') %you must set the domain and range %you can also use the line options %Polar %plots polar coordinates theta = [0:.1:2*pi]; r = 1 + cos(theta); figure; polar(theta,r); %Formatting 1 %xlabel('x axis label goes here'), labels the x axis %ylabel('y axis label goes here'), labels the y axis %title('title goes here'), places a title %axis([xmin xmax ymin ymax]), sets the limits of the graph 2 3 4 5 Published with MATLAB® R2014a 6