PH36010 Numerical Methods Advanced Plotting and Animation Advanced Plotting in MathCAD • Polar Plots • 3D Plots – – – – Surface Contour Scatter Bar • Vector Field Plots Polar Plots #1 • X-Y Plot wrapped around a circle r=cos2() 90 1 20 1 60 0 .8 0 .6 1 50 30 0 .4 0 .2 F( ) 1 80 0 0 2 10 3 30 2 40 3 00 2 70 0 33 3 .7 491 Polar Plots #2 k •r=e k 0.2 r e k 0 0.1 6 90 1 20 40 60 30 1 50 30 20 10 r 1 80 0 0 2 10 3 30 2 40 3 00 2 70 Uses for Polar Plots • Rotating Machines – Stirling engine – Vibration • Arctic & Antarctic systems 3D surface plots Simple #1 • Plot of data stored in array • Indices of array represent x-y plane • Value of matrix is z value – – – – Define size of matrix & indices Determine values for x & y Fill matrix Plot 3D surface plots Simple #2 N 100 xi 0 N 5 0.1i f( x y) Mi j i e 2 x f xi yj yj y 2 j 0 N 5 0.1j • Define size & indices • Define Range for x & y • 2D-Gaussian • Fill matrix 3D surface plots Simple #3 M 3D surface plots Simple #4 – Lighting M Contour Plot - from 3d plot data • Format plot type -> Contour plot M Simple 3D plots Limitations • X & Y axes scaled in indices • Suited to continuous single valued functions • More advanced 3D plots available 3D Scatter plot • Plot of individual points • Supply with 3 vectors of equal length (X,Y,Z) • Points plotted: – X0,Y0,Z0 – X1,Y1,Z1 –… 3D scatter plot Photon Scatter in 3D ( XX YY ZZ) 3D surface plots Parametric Plot • Plot complex surfaces • From Resource Centre Guide to 3D plotting ( X Y Z) 3D parametric plot Example - 1002 for H X- & YAxes scaled in m ( X Y Z100 ) Parametric Plots How to… #1 • • • • • • Rubber sheet N x M Wrap sheet around surface XXa,b is x-coord of point a,b YYa,b is y-coord of point a,b ZZa,b is z-coord of point a,b (XX,YY,ZZ) will plot surface Parametric Plots Example 1 - Gaussian N 100 xmin 5 xmax 5 x xmax xmin ymin 5 ymax 5 y ymax ymin i 0 N j xmin x i YYi j ymin y j f( x y) ZZi j e N 0 N XXi j 2 x N • Ranges defined as before y 2 f XXi j YYi j • Fill XX & YY matrices • Fill ZZ matrix Parametric Plots Example 1 - Gaussian • Note: – Axes scaled ( XX YY ZZ) The SeriesVector() program SeriesVector( Start Finish nSteps ) Finish Start nSteps for i 0 nSteps Resulti Start i Result (increment) and i (loop count) are ‘local’ to function. Function builds Result vector Returned on last line of program Parametric Plots Polar 3D #1 nr r n Xi j 100 i 0 nr SeriesVector 0 m 10 a 0 nr 30 j 0 n SeriesVector ( n) ricos j Yi j risin j • Create r vector 0-10 radii, 100 teps • Create vector -180..180 deg, 30 steps • Fill X & Y vectors Paramteric Plots Polar 3D #2 r 100 ( r ) a0 Define 100 function a e 0 1 3 2 Z100i j 3 a 0 100 ri Fill Z matrix with 100 function NB Only depends on r 3D parametric plot Example - 1002 for H X- & YAxes scaled in m ( X Y Z100 ) Plot of 2102 for H • X & Y matrices as before • Z now depends on r,q r 210 ( r ) 1 r e 2 a 0 cos ( ) 32 a 0 5 2 Z210i j 3 a 0 210 ri j 3D parametric plot Example - 2102 for H ( X Y Z210 ) Pretty Pictures From Resource Centre Plot multiple Surfaces Pretty Pictures #3 Planetary Orbit • 3 objects – Planet : (xe,ye,ze) – Star : (xs,ys,zs) – Orbit: (xp,yp,zp) ( xe ye ze) ( xs ys zs) ( xp yp zp) Animation Principles • Make output depend on FRAME • Tools|Animation|Record… to display dialog – – – – – Fill in first & last frames Drag cursor around area to animate Select ‘Animate’ to go View with AVI player Save to disk • Help|Quicksheets|Graphing and Visualization Animation Hints and Tips • Fix scale of graphs • Watch out for: – Size of AVI files – Long calculation times • Can test by using FRAME:= – Delete afterwards • Put indicator in movie Animation Example #1 Cannon Ball with drag Animation Example #2 LCR at resonance Animation Example #3 Heat Flow in Plate Animation Example #4 Planetary Orbits 3D with lighting & shadows