matlab what is code segment calculating? -


i have being trying figure out matlab code doing. takes 3 data points x , corresponding y values:

x ,y

and fit:

fy = polyfit(x, y, 2) 

which second order fit of 3 x, y data points.

then followed line of code:

u = -fy(2) / (2*fy(1)) 

this seems calculate x value in range between x(1) , x(3) i'm not sure calculating? why multiplying fy(1) value 2?

fy(1) coefficient of x^2 term, , fy(2) coefficient x term. 2* makes me think derivative, let's see looks like. first original quadratic fit:

fy(1)*x^2 + fy(2)*x + fy(3) 

now derivative:

2*fy(1)*x + fy(2) 

ahah, starting familiar. setting equal 0 , solving x?

2*fy(1)*x + fy(2) = 0 2*fy(1)*x = -fy(2) x = -fy(2) / (2*fy(1)) 

yep, that's it. it's computing x location derivative of quadratic fit equals zero. , happens @ place first derivative of curve equals zero? maximum or minimum.

so, code finds x coordinate of max or min of quadratic fit of data. accurate peak finder?


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -