An Introduction to MathCAD Animation, Interpolation and other pretty pictures 1 1
Animation Example Example from our LCR circuit
Animation #2 Basics Use FRAME variable FRAME automatically set by mathCAD for each frame of animation Select View|Animation… to bring up animation dialog Give start & end values for FRAME Select area to animate Select Animate to produce Save As… to create .avi file
Animation #3 Hints “Error initialising Video Stream” => Nothing Selected May want to scale FRAME Animations can: Take a long time to create Produce big files Windows video player allows thumb bar to step forward & back
Animation #4 More Hints Fix scale on graphs Don’t need to include calculations in animation Echo FRAME= in shot If scaling, echo scaled variable For frequency plots, scale FRAME thus:
Vector Field Plots #1 Plot matrix of complex numbers Each point shown as vector Plot scaled so that largest vector is gap between points Useful for: Electric fields Magnetic fields Dynamic Flows Plotting Gradient of functions
Vector Field Plots #2
Data Analysis #1 Get data from file Read data in from datafile Use either: Insert|Component|File Read or Write & follow the wizard READPRN(“filename”) Reads data from file into vector or matrix File Read component offers many more file types
Data Analysis #2 Select the data we want Use matrix functions to select data we are interested in Rows(M) & Cols(M) to get size of data array Submatrix(M,rs,rf,cs,cf) to select rectangular chunk M<x> to select column Csort to sort array Augment & stack to build arrays
Data Analysis #3 Smoothing Data medsmooth(vy,n) returns vy smoothed with running medians
Data Analysis #4 Linear regression Slope & intercept functions take vectors of X & Y values
Data Analysis #5 Interpolation 2 stage process Fit polynomial through points cspline – cubic spline Bspline – B-spline Interpolate using polynomial obtained in stage 1 interp
Cubic Spline fit & Interpolated Fit
Function Fitting Cspline & Bspline fit smooth curve through data points In physical modelling, we know the shape of the function to fit, just need parameters Example: Response of photon counting detector
Function Fitting Example #1 Determine parameters a & b
Function Fitting Example #2 Rewrite f(x) and derivatives Replace a,b by u0, u1… Find partial derivatives of f(x) Create vector of function & pds
Function fitting Example #3 Create vector of guess values Call genfit to solve Define function using params
Function Fitting Example #4 Plot f(x) against data