11.07.2015 Views

MatlabNotes

MatlabNotes

MatlabNotes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

YData: [27 8 1]ZData:[1x0 double]The colour is described by a rgb triple in which[0 0 0] denotes black and [1 1 1] denoteswhite. Properties can be changed with the setcommand, for example>> set(plt,’markersize’,12)will change the size of the marker symbol ’o’while>> set(plt,’linestyle’,’:’,’ydata’,[1 8 27])will change the lifestyle from dashed to dottedwhile also changing the y–coordinates of thedata points. The commands>> x = 0:.01:1; y=sin(3*pi*x);>> plot(x,y,’k-’,x,cos(3*pi*x),’g--’)>> legend(’Sin curve’,’Cos curve’)>> title(’Multi-plot ’)>> xlabel(’x axis’), ylabel(’y axis’)>> set(gca,’fontsize’,16,...’ytick’,-1:.5:1);redraw Fig. 3 and the last line sets the fontsize to 16points and changes the tick-marks onthe y-axis to 1, 0.5, 0, 0.5, 1—see Fig. 4. The... in the penultimate line tell Matlab that theline is split and continues on the next line.Example 13.1 Plot the first 100 terms in thesequence {y n } given by y n = 1+ 1 nn and illustratehow the sequence converges to the limite = exp(1) = 2.7183.... as n !1.Exercises such as this that require a certainamount of experimentation are best carried outby saving the commands in a script file. Thecontents of the file (which we call latexplot.m)are:close allfigure(1);set(0,’defaultaxesfontsize’,12)set(0,’defaulttextfontsize’,16)set(0,’defaulttextinterpreter’,’latex’)N = 100; n = 1:N;y = (1+1./n).^n;subplot(2,1,1)plot(n,y,’.’,’markersize’,8)hold onaxis([0 N,2 3])plot([0 N],[1, 1]*exp(1),’--’)text(40,2.4,’$y_n = (1+1/n)^n$’)text(10,2.8,’y = e’)xlabel(’$n$’), ylabel(’$y_n$’)The results are shown in the upper part of Fig. 5.Fig. 4: Repeat of Fig. 3 with a font size of16points and amended tick marks on the y-axis.13.10 Formatted text on PlotsIt is possible to typeset simple mathematicalexpressions (using L A TEX commands) in labels,legends, axes and text. We shall give two illustrations.Fig. 5: The output from Example 13.1 (top)and Example 13.2 (bottom).The salient features of these commands are1. The set commands in lines 3–4 increasethe size of the default font size used for15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!