Presentation is loading. Please wait.

Presentation is loading. Please wait.

PH24010 MathCAD More Curve Fitting. Previously on PH24010 Linear Fitting slope(), intercept() line() Pre-process Y-data: –y = k/x –y = e kx.

Similar presentations


Presentation on theme: "PH24010 MathCAD More Curve Fitting. Previously on PH24010 Linear Fitting slope(), intercept() line() Pre-process Y-data: –y = k/x –y = e kx."— Presentation transcript:

1 PH24010 MathCAD More Curve Fitting

2

3 Previously on PH24010 Linear Fitting slope(), intercept() line() Pre-process Y-data: –y = k/x –y = e kx

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

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

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

7 Lightbulb Example Quadratic A + B x + C x 2 Call linfit() to get coeffients

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

9 Compare model with data

10 Peak fitting Applications in spectroscopy Gaussian peak need to find: –position –amplitude –background –width

11 Gaussian Peak Fit

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

13 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

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

15 Form Partial Derivatives Use symbolic differentiation

16 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 P 0, P 1, P 2

17 Vector function for Gaussian fit Function to fit dF/dP 0 dF/dP 1 dF/dP 2 dF/dP 3

18 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 (  ) = -3 P3 is the width of the peak at half amplitude (w) = 2

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

20 Plot model with data


Download ppt "PH24010 MathCAD More Curve Fitting. Previously on PH24010 Linear Fitting slope(), intercept() line() Pre-process Y-data: –y = k/x –y = e kx."

Similar presentations


Ads by Google