Post on 18-Dec-2015
PH36010 PH36010 Numerical MethodsNumerical Methods
Advanced Plotting and AnimationAdvanced Plotting and Animation
Advanced Plotting in Advanced Plotting in MathCADMathCAD
• Polar PlotsPolar Plots• 3D Plots3D Plots
– SurfaceSurface– ContourContour– ScatterScatter– BarBar
• Vector Field PlotsVector Field Plots
Polar Plots #1Polar Plots #1
• X-Y Plot wrapped around a circleX-Y Plot wrapped around a circle
0
30
60
90
120
150
180
210
240
270
300
330
0.8
0.6
0.4
0.2
0
1
3.7491033F ( )
r=cosr=cos22(())
Polar Plots #2Polar Plots #2k 0.2
r ek 0 0.1 6
0
30
60
90
120
150
180
210
240
270
300
330
40
30
20
10
0r
•r=er=ekk
Uses for Polar PlotsUses for Polar Plots
• Rotating MachinesRotating Machines– Stirling engineStirling engine– VibrationVibration
• Arctic & Antarctic systemsArctic & Antarctic systems
3D surface plots3D surface plotsSimple #1Simple #1
• Plot of data stored in arrayPlot of data stored in array• Indices of array represent x-y planeIndices of array represent x-y plane• Value of matrix is z valueValue of matrix is z value
– Define size of matrix & indicesDefine size of matrix & indices– Determine values for x & yDetermine values for x & y– Fill matrixFill matrix– PlotPlot
3D surface plots3D surface plotsSimple #2Simple #2
• Define size & Define size & indicesindices
• Define Range Define Range for x & yfor x & y
• 2D-Gaussian2D-Gaussian
• Fill matrixFill matrix
N 100 i 0 N j 0 N
xi 5 0.1 i yj 5 0.1 j
f x y( ) ex2
y2
Mi j f xi yj
3D surface plots3D surface plotsSimple #3Simple #3
M
3D surface plots3D surface plotsSimple #4 – LightingSimple #4 – Lighting
M
Contour PlotContour Plot- from 3d plot data- from 3d plot data
• Format plot type -> Contour plotFormat plot type -> Contour plot
M
Simple 3D plotsSimple 3D plotsLimitationsLimitations
• X & Y axes scaled in indicesX & Y axes scaled in indices
• Suited to continuous single valued Suited to continuous single valued functionsfunctions
• More advanced 3D plots availableMore advanced 3D plots available
3D Scatter plot3D Scatter plot
• Plot of individual pointsPlot of individual points• Supply with 3 vectors of equal Supply with 3 vectors of equal
length (X,Y,Z)length (X,Y,Z)• Points plotted:Points plotted:
– XX00,Y,Y00,Z,Z00
– XX11,Y,Y11,Z,Z11
– ……
3D scatter plot3D scatter plotPhoton Scatter in 3DPhoton Scatter in 3D
XX YY ZZ( )
3D surface plots3D surface plotsParametric PlotParametric Plot
• Plot complex surfacesPlot complex surfaces• From Resource Centre Guide to 3D From Resource Centre Guide to 3D
plottingplotting
X Y Z( )
3D parametric plot3D parametric plotExample - Example - 100100
22 for H for H
X Y Z100( )
X- & Y-X- & Y-Axes Axes scaled scaled in min m
Parametric PlotsParametric PlotsHow to… #1How to… #1
• Rubber sheet N x MRubber sheet N x M• Wrap sheet around surfaceWrap sheet around surface
• XXXXa,ba,b is x-coord of point a,b is x-coord of point a,b
• YYYYa,ba,b is y-coord of point a,b is y-coord of point a,b
• ZZZZa,ba,b is z-coord of point a,b is z-coord of point a,b
• (XX,YY,ZZ) will plot surface(XX,YY,ZZ) will plot surface
Parametric PlotsParametric PlotsExample 1 - GaussianExample 1 - Gaussian
• Ranges defined Ranges defined as beforeas before
• Fill XX & YY Fill XX & YY matricesmatrices
• Fill ZZ matrixFill ZZ matrix
N 100
xmin 5 xmax 5 xxmax xmin
N
ymin 5 ymax 5 yymax ymin
N
i 0 N j 0 N
XXi j xmin x i
YYi j ymin y j
f x y( ) ex2
y2
ZZi j f XXi j YYi j
Parametric PlotsParametric PlotsExample 1 - GaussianExample 1 - Gaussian
• Note:Note:– Axes Axes
scaledscaled
XX YY ZZ( )
The SeriesVector()The SeriesVector()programprogram
SeriesVector Start Finish nSteps( ) Finish Start
nSteps
Resulti Start i
i 0 nStepsfor
Result
(increment) and (increment) and ii (loop count) are (loop count) are ‘local’ to function.‘local’ to function.Function builds Result vectorFunction builds Result vectorReturned on last line of programReturned on last line of program
Parametric PlotsParametric PlotsPolar 3D #1Polar 3D #1
• Create r vectorCreate r vector0-10 radii, 100 0-10 radii, 100 tepsteps
• Create Create vector vector-180..180 deg, -180..180 deg, 30 steps30 steps
• Fill X & Y vectorsFill X & Y vectors
nr 100 i 0 nr
r SeriesVector 0 m 10 a 0 nr
n 30 j 0 n
SeriesVector n( )
Xi j ri cos j Yi j ri sin j
Paramteric PlotsParamteric PlotsPolar 3D #2Polar 3D #2
100 r( )1
a 03
e
r
a 0
Z100i j a 03 100 ri
2
Define Define 100 function100 function
Fill Z matrix withFill Z matrix with 100 function100 function
NB Only depends on NB Only depends on rr
3D parametric plot3D parametric plotExample - Example - 100100
22 for H for H
X Y Z100( )
X- & Y-X- & Y-Axes Axes scaled scaled in min m
Plot of Plot of 21021022 for H for H
• X & Y matrices as beforeX & Y matrices as before• Z now depends on r,qZ now depends on r,q
210 r ( )1
32 a 05
r e
r
2 a 0
cos ( )
Z210i j a 03 210 ri j
2
3D parametric plot3D parametric plotExample - Example - 210210
22 for H for H
X Y Z210( )
Pretty PicturesPretty Pictures From Resource Centre From Resource Centre
Plot multiple SurfacesPlot multiple Surfaces
Pretty Pictures #3Pretty Pictures #3 Planetary Orbit Planetary Orbit
• 3 objects3 objects– Planet : (xe,ye,ze)Planet : (xe,ye,ze)– Star : (xs,ys,zs)Star : (xs,ys,zs)– Orbit: (xp,yp,zp)Orbit: (xp,yp,zp)
xe ye ze( ) xs ys zs( ) xp yp zp( )
AnimationAnimation Principles Principles
• Make output depend on FRAMEMake output depend on FRAME• Tools|Animation|Record…Tools|Animation|Record…
to display dialog to display dialog– Fill in first & last framesFill in first & last frames– Drag cursor around area to animateDrag cursor around area to animate– Select ‘Animate’ to goSelect ‘Animate’ to go– View with AVI playerView with AVI player– Save to diskSave to disk
• Help|Quicksheets|Graphing and Help|Quicksheets|Graphing and VisualizationVisualization
AnimationAnimationHints and TipsHints and Tips
• Fix scale of graphsFix scale of graphs• Watch out for:Watch out for:
– Size of AVI filesSize of AVI files– Long calculation timesLong calculation times
• Can test by usingCan test by usingFRAME:=FRAME:=– Delete afterwardsDelete afterwards
• Put indicator in moviePut indicator in movie
Animation Example #1Animation Example #1 Cannon Ball with drag Cannon Ball with drag
Animation Example #2Animation Example #2LCR at resonanceLCR at resonance
Animation Example #3Animation Example #3Heat Flow in PlateHeat Flow in Plate
Animation Example #4Animation Example #4Planetary OrbitsPlanetary Orbits
3D with lighting & 3D with lighting & shadowsshadows