DOC PREVIEW
GT AE 6382 - AE 6382-2D Plotting in Matlab

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

2D Plotting in MatlabTwo Dimensional PlottingBackgroundBasic 2D PlottingSupporting CommandsUsing Lines or Markers or Both…Using Both Markers & LinesPlotting Multiple CurvesPlotting Multiple Curves (cont’d)Using 2 Y-axis ScalesBasic Plot CommandsExample of Log PlotsSubplot CommandOn Your Own:Specialized 2D PlotsA Special M-function: fevalfeval - continuedUse of feval in an M-functionUsing Your New Function: evaluate()A More Complicated ExampleUsing fminbnd()A Note on How Arguments are PassedApplication: Solving ODE’sSolving an ODE: setupMatlab ode45( ) Syntaxrhs( ) function for ode45( )Solving the Problem…A More Interesting RHS…SummaryFall 2006AE6382 Design Computing 12D Plotting in MatlabLearning ObjectivesDiscover how Matlab can be used to construct 2D plots.Topics•Structure of a 2D plot•Command syntax•Types of 2D plots•Applications…•SummaryFall 2006AE6382 Design Computing 2Two Dimensional PlottingLearning Objectives–Understand the anatomy of a 2D plot–How to choose different plot types for best effectsTopics–Construction of 2D plots using plot()–Modification and enhancements to the plot–Different types of 2D plots you can createFall 2006AE6382 Design Computing 3Background•While numerical methods are the heart (and origin) of Matlab, graphics has become the major component since the release of Version 4.•Version 6 adds to this legacy with refinements and new functions.•Professional Matlab comes with two thick manuals: (a) basic commands & programming and (b) graphics•The graphics capabilities are so broadly defined that we will be able to cover only a small part–we'll focus on graphics you will find immediately useful–we will point to some of the areas where you will find powerful new capabilities when you need them later•Like all of us, you will find yourselves frequently looking up "help" or checking the manuals for graphics!Fall 2006AE6382 Design Computing 40 5 10 15 20 25 30 35-1-0.500.51X axis descriptionY axis descriptionTitle for plot goes hereLegend for graphManually inserted text... >> x=0:0.05:10*pi;>> y=exp(-.1.*x).*sin(x);>> plot(x,y)>> xlabel('X axis description')>> ylabel('Y axis description')>> title('Title for plot goes here')>> legend('Legend for graph')>> grid onBasic 2D Plotting•The simplest kind of plot is a cartesian plot of (x,y) pairs defined by symbols or connected with linesNOTE #1:Reversing the x,y order (y,x) simply rotates the plot 90 degrees!NOTE #2:line(x,y) is similar to plot(x,y) but does not have additional optionsFall 2006AE6382 Design Computing 5Supporting Commands•Several functions let you control the plot appearance–axis(): determines the axis scaling (see help for options)–hold on/off: controls whether or not the plot is erased before another plot is drawn (toggles if no argument given)>> x=0:0.1:2*pi;>> plot(x,sin(x))>> axisans = 0 7 -1 1>> axis([0 7 -.5 .5])0 1 2 3 4 5 6 7-0.500.5>> x=0:0.1:2*pi; >> plot(x,sin(x))>> hold on>> plot(x,cos(x))0 2 4 6 8-1-0.500.51Fall 2006AE6382 Design Computing 6Using Lines or Markers or Both…•Plots must follow the following logic:–Lines: whenever plotting analytical functions like sin(x) where you can compute y for any value of x–Markers: whenever plotting discrete experimental data or whenever the data are known only discretely–Both: connecting markers with straight lines is appropriate when you want to show a sequence>> plot(x,cos(x),'r:')>> hold on>> plot(x,sin(x),'b--')0 2 4 6 8-1-0.500.510 0.2 0.4 0.6 0.8 1-0.200.20.40.60.811.2>> x=0:.02:1;>> y=x.^1.5;>> yr=randn(size(x));>> yy=y+0.1.*yr;>> plot(x,yy,'ro',x,yy)0 0.2 0.4 0.6 0.8 1-0.200.20.40.60.811.2>> x=0:0.02:1;>> y=x.^1.5;>> yr=randn(size(x));>> yy=y+0.1.*yr;>> plot(x,yy,'rx')Fall 2006AE6382 Design Computing 7Using Both Markers & Lines•Use lines to show analytical fit through discrete data>> x=0:.02:1;>> y=x.^1.5;>> yr=randn(size(x));>> yy=y+0.1.*yr;>> plot(x,yy,'x')>> p=polyfit(x,yy,1)p = 1.0159 -0.0927>> hold on>> plot(x,polyval(p,x),'r')0 0.2 0.4 0.6 0.8 1-0.200.20.40.60.811.20 2 4 6 8-15-10-5051015>> x=0:0.2:2.*pi;>> y=sin(x);>> yr=randn(size(x));>> plot(x,10.*y+yr,'ro')>> hold on>> plot(x,10.*y)Fall 2006AE6382 Design Computing 8Plotting Multiple Curves•Problem: How can you compare several curves?•Let’s start with the following:•We could plot these using:>> X = 0.0:pi/100:2*pi;>> Y1 = cos(X);>> Y2 = 3*cos(X);>> Y3 = cos(2*X);>> Y4 = sin(X);>> plot(X,Y1)>> hold on>> plot(X,Y2)>> plot(X,Y3)>> plot(X,Y4)0 1 2 3 4 5 6 7-3-2-10123Fall 2006AE6382 Design Computing 9Plotting Multiple Curves (cont’d)•Or we could do:•Or we could do this:•What if we did this?•Do a “help plot” for more markers.•How could we see the data points more distinctly?0 1 2 3 4 5 6 7-3-2-10123>> plot(X,Y1,X,Y2,X,Y3,X,Y4)>> Z = [Y1;Y2;Y3;Y4];>> plot(X,Z)0 1 2 3 4 5 6 7-3-2-10123>> plot(X, Z, 'o')Fall 2006AE6382 Design Computing 10Using 2 Y-axis Scales•Sometimes it is useful to plot two curves with widely different y-axis scales>> x=0:0.1:3.*pi;>> y1=sin(x+0.5);>> y2=90.*sin(x-0.5);>> plotyy(x,y1,x,y2)0 2 4 6 8 10-1-0.500.510 2 4 6 8 10-100-500501000 2 4 6 8 10-100-50050100>> x=0:0.1:3.*pi;>> y1=sin(x+0.5);>> y2=90.*sin(x-0.5);>> plot(x,y1,x,y2)NOTE: it is complicated to label the 2nd axis…Fall 2006AE6382 Design Computing 11Basic Plot Commands •axis - freezes current axis scaling•axis([xmin, xmax, ymin, ymax]) – sets axis limit values (note use of [ ] )•axis off – turns off display of axes (plot unchanged)•axis on – turns on display of axes•grid on/off – turns on/off display of a grid•text(x,y,‘string’) - places horizontal text starting at (x,y)•gtext(‘string’) – places horizontal text starting wherever user clicks with mouse•line(x,y) – adds line specified by x & y vectorsFall 2006AE6382 Design Computing 12Example of Log Plots•Using a log scale can reveal large dynamic ranges>> x=linspace(.1,10,1000);>> damp=0.05;>> y=1./sqrt((1-x.^2).^2 + (2.*damp.*x).^2);>> plot(x,y)>> semilogx(x,y)>> loglog(x,y)0 2 4 6 8 10024681010-1100101024681010-110010110-210-1100101Describes the behavior of vibrating systems1/ 22 2 21(1 ) (2 )yx xz=� �- +� �Fall 2006AE6382 Design Computing 13Subplot Command•There are times when it is better to create several smaller plots arranged in some kind of grid; subplot(m,n,k) does this…–m=rows, n=columns in the grid –k=current focus (numbered row-wise)•Let’s define a 2x3 subplot grid for:


View Full Document

GT AE 6382 - AE 6382-2D Plotting in Matlab

Download AE 6382-2D Plotting in Matlab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view AE 6382-2D Plotting in Matlab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view AE 6382-2D Plotting in Matlab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?