12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

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.

10: y = linspace(ycentre - L,ycentre + L,N);0.13s, 0% 11: [X,Y] = meshgrid(x,y);0.67s, 2% 12: Z = X + i*Y;13 : Z0 = Z;14: for k = 1:50;23.02s, 76% 15: Z = Z.^2 + Z0;0.02s, 0% 16: end0.36s, 1% 17: ind1 = find(isnan(Z));0.43s, 1% 18: ind2 = find(~isnan(Z));0.22s, 1% 19: Z(ind1) = 1;0.08s, 0% 20: Z(ind2) = 0;5.15s, 17% 21: contour(x,y,abs(Z),[.5 .5])0.02s, 0% 22: grid;box23: axis equal <strong>of</strong>fMost <strong>of</strong> the time here is spent iterating the values <strong>of</strong> Z. You can geta plot <strong>of</strong> the time taken by the most time-consuming lines <strong>of</strong> code bycapturing the output <strong>of</strong> the pr<strong>of</strong>ile comm<strong>and</strong> <strong>and</strong> using it to produce apareto chart:>> t = pr<strong>of</strong>ilet =file: [ 1x64 char ]interval: 0.0100count: [23x1 double]state: ’<strong>of</strong>f’>> pareto(t.count)7733600040002000015 12 21100%78%52%26%0%Here only the three most time-consuming lines (labelled on the x axis)are shown, the rest taking too little time to be <strong>of</strong> concern. The left-h<strong>and</strong>scale shows the time taken to do each line, in hundredths <strong>of</strong> a second.The line is the cumulative time. If we wanted to speed up this code, wewould do well to concentrate on line 15, <strong>and</strong> forget trying to speed upthe graphics.Pr<strong>of</strong>ile in <strong>MATLAB</strong> 5.3The pr<strong>of</strong>ile comm<strong>and</strong> has been significantly exp<strong>and</strong>ed in matlab 5.3.Use pr<strong>of</strong>ile on to switch on the pr<strong>of</strong>iler. A hypertext report is producedby typing pr<strong>of</strong>ile report. A graphical display <strong>of</strong> the pr<strong>of</strong>ileresults is obtained by typing pr<strong>of</strong>ile plot.c○ 2000 by CRC Press LLC

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

Saved successfully!

Ooh no, something went wrong!