Functions > Data Analysis > Curve Fitting > Example: Rational Function Regression 2
Example: Rational Function Regression 2
rationalfitnp - No Poles
Use the rationalfit and rationalfitnp functions to perform rational function regression. When you use the rationalfitnp function instead of the rationalfit function, the solution to the traditional least-squares problem is checked for roots of the denominator within the fitting interval. If there are no poles, the generated fit is returned. If there are poles, additional constraints are added to the nonlinear optimization problem.
1. Define a data set by modifying slightly the inverse function of x.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Specify an order for the numerator and denominator of the rational function.
Click to copy this expression
Click to copy this expression
The fitting function has the following form:
Click to copy this expression
3. Define a confidence limit and a vector of standard deviations.
Click to copy this expression
Click to copy this expression
4. Call the rationalfit and the rationalfitnp functions.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
For param1 and param2, the first column contains the parameters and the remaining columns contain the lower and the upper boundaries for each parameter at the confidence limit defined above.
5. Plot the data set and the two regression curves.
Click to copy this expression
Click to copy this expression
Click to copy this expression
The pole was removed by the rationalfitnp function. Its denominator polynomial is cast in the following form:
Click to copy this expression
To avoid the pole, the following constraints were added:
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
LeastSquaresFit
Compare the fitting curves returned by rationalfitnp and by LeastSquaresFit. The LeastSquaresFit function performs the same algorithm as the one for rationalfitnp, but it requires guess values and confidence limits for the parameters. You may wish to do this when you want the constant term to be in the numerator rather than in the denominator.
1. Define the fitting function.
Click to copy this expression
2. Define guess values for the parameters.
Click to copy this expression
3. Define lower and upper boundary conditions for the parameters.
Click to copy this expression
4. Call the LeastSquaresFit function.
Click to copy this expression
5. Plot the data set, and the fitting curves returned by the rationalfitnp, and the LeastSquaresFit functions.
Click to copy this expression
Click to copy this expression
* 
Any filtering or data transformation method that biases the data towards a straight line before doing a rational function fit will add considerable convergence speed to the rational function and may have a side benefit of getting rid of unwanted poles.
Was this helpful?