1 / 20

PH24010

PH24010. MathCAD More Curve Fitting. Previously on PH24010. Linear Fitting slope(), intercept() line() Pre-process Y-data: y = k/x y = e kx. What when can’t pre-process ?. eg. y = a + bx + cx 2 Current through light bulb R changes with heat. linfit().

kelly-cox
Download Presentation

PH24010

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PH24010 MathCAD More Curve Fitting

  2. Previously on PH24010 • Linear Fitting • slope(), intercept() • line() • Pre-process Y-data: • y = k/x • y = ekx

  3. What when can’t pre-process ? • eg. • y = a + bx + cx2 • Current through light bulb • R changes with heat

  4. linfit() • Fitting routine for ‘linear’ combinations of functions. • eg: y = A + B ln(x) + C ex + D x3 Find A,B,C & D to give best fit to data. • Needs ‘vector of functions’

  5. A vector of functions • Define function of variable x • Create vector with n rows & 1 column • Fill placeholders with expressions involving x

  6. Lightbulb Example • Quadratic • A + B x + C x2 • Call linfit() to get coeffients

  7. Create model from linfit() results • Explicitly put Coeffs into model • better to use vector maths…(dot product)

  8. Compare model with data

  9. Peak fitting • Applications in spectroscopy • Gaussian peak • need to find: • position • amplitude • background • width

  10. Gaussian Peak Fit

  11. genfit() • Generalised fit of any function • Need: • model function • partial derivatives of model wrt parameters • vector of initial guesses for each parameter

  12. Gaussian Peak Function • Where: • y0 is the background level • m is the x value of the peak centre • w is the width of the peak at half amplitude • A is the amplitude of the peak maximum

  13. Function parameters • Re-write as P0, P1, P2 … P0 is the background level (y0) P1 is the amplitude of the peak maximum (A) P2 is the x value of the peak centre (m) P3 is the width of the peak at half amplitude (w)

  14. Form Partial Derivatives • Use symbolic differentiation

  15. Create Function Vector for genfit() • Function takes 2 parameters: • Independent variable, x • Parameter Vector, P • Re-write P0,P1,P2 etc to use vector subscripts P0, P1, P2

  16. Vector function for Gaussian fit • Function to fit • dF/dP0 • dF/dP1 • dF/dP2 • dF/dP3

  17. Guess Values for Parameters • By inspection of graph P0 is the background level (y0) = 2 P1 is the amplitude of the peak maximum (A) = 6 P2 is the x value of the peak centre (m) = -3 P3 is the width of the peak at half amplitude (w) = 2

  18. Call genfit() • Form model as before from coeffients & fit function Use vector subscript to extract correct function from vector function

  19. Plot model with data

More Related