ph36010 numerical methods advanced plotting and animation

33
PH36010 PH36010 Numerical Methods Numerical Methods Advanced Plotting and Animation Advanced Plotting and Animation

Upload: alan-chase

Post on 18-Dec-2015

252 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: PH36010 Numerical Methods Advanced Plotting and Animation

PH36010 PH36010 Numerical MethodsNumerical Methods

Advanced Plotting and AnimationAdvanced Plotting and Animation

Page 2: PH36010 Numerical Methods Advanced 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

Page 3: PH36010 Numerical Methods Advanced Plotting and Animation

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(())

Page 4: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 5: PH36010 Numerical Methods Advanced Plotting and Animation

Uses for Polar PlotsUses for Polar Plots

• Rotating MachinesRotating Machines– Stirling engineStirling engine– VibrationVibration

• Arctic & Antarctic systemsArctic & Antarctic systems

Page 6: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 7: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 8: PH36010 Numerical Methods Advanced Plotting and Animation

3D surface plots3D surface plotsSimple #3Simple #3

M

Page 9: PH36010 Numerical Methods Advanced Plotting and Animation

3D surface plots3D surface plotsSimple #4 – LightingSimple #4 – Lighting

M

Page 10: PH36010 Numerical Methods Advanced Plotting and Animation

Contour PlotContour Plot- from 3d plot data- from 3d plot data

• Format plot type -> Contour plotFormat plot type -> Contour plot

M

Page 11: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 12: PH36010 Numerical Methods Advanced Plotting and Animation

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

– ……

Page 13: PH36010 Numerical Methods Advanced Plotting and Animation

3D scatter plot3D scatter plotPhoton Scatter in 3DPhoton Scatter in 3D

XX YY ZZ( )

Page 14: PH36010 Numerical Methods Advanced Plotting and Animation

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( )

Page 15: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 16: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 17: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 18: PH36010 Numerical Methods Advanced Plotting and Animation

Parametric PlotsParametric PlotsExample 1 - GaussianExample 1 - Gaussian

• Note:Note:– Axes Axes

scaledscaled

XX YY ZZ( )

Page 19: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 20: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 21: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 22: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 23: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 24: PH36010 Numerical Methods Advanced Plotting and Animation

3D parametric plot3D parametric plotExample - Example - 210210

22 for H for H

X Y Z210( )

Page 25: PH36010 Numerical Methods Advanced Plotting and Animation

Pretty PicturesPretty Pictures From Resource Centre From Resource Centre

Plot multiple SurfacesPlot multiple Surfaces

Page 26: PH36010 Numerical Methods Advanced Plotting and Animation

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( )

Page 27: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 28: PH36010 Numerical Methods Advanced Plotting and Animation

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

Page 29: PH36010 Numerical Methods Advanced Plotting and Animation

Animation Example #1Animation Example #1 Cannon Ball with drag Cannon Ball with drag

Page 30: PH36010 Numerical Methods Advanced Plotting and Animation

Animation Example #2Animation Example #2LCR at resonanceLCR at resonance

Page 31: PH36010 Numerical Methods Advanced Plotting and Animation

Animation Example #3Animation Example #3Heat Flow in PlateHeat Flow in Plate

Page 32: PH36010 Numerical Methods Advanced Plotting and Animation

Animation Example #4Animation Example #4Planetary OrbitsPlanetary Orbits

Page 33: PH36010 Numerical Methods Advanced Plotting and Animation

3D with lighting & 3D with lighting & shadowsshadows