Main Content

Rational Polynomials

About Rational Models

Rational models are defined as ratios of polynomials and are given by

y=i=1n+1pixn+1ixm+i=1mqixm1

where n is the degree of the numerator polynomial and 0 ≤ n ≤ 5, while m is the degree of the denominator polynomial and 1 ≤ m ≤ 5. Note that the coefficient associated with xm is always 1. This makes the numerator and denominator unique when the polynomial degrees are the same.

Here rationals are described in terms of the degree of the numerator/the degree of the denominator. For example, a quadratic/cubic rational equation is given by

y=p1x2+p2x+p3x3+q1x2+q2x+q3

Like polynomials, rationals are often used when a simple empirical model is required. The main advantage of rationals is their flexibility with data that has a complicated structure. The main disadvantage is that they become unstable when the denominator is around 0. For an example that uses rational polynomials of various degrees, see Example: Rational Fit.

Fit Rational Models Interactively

  1. Open the Curve Fitter app by entering curveFitter at the MATLAB® command line. Alternatively, on the Apps tab, in the Math, Statistics and Optimization group, click Curve Fitter.

  2. In the Curve Fitter app, select curve data. On the Curve Fitter tab, in the Data section, click Select Data. In the Select Fitting Data dialog box, select X Data and Y Data, or just Y Data against an index.

  3. Click the arrow in the Fit Type section to open the gallery, and click Rational in the Regression Models group.

Fit Options pane for rational fit

You can specify the following options in the Fit Options pane:

  • Specify the numerator degree as a nonnegative integer in the range [0 5] and the denominator degree as a positive integer in the range [1 5]. Look in the Results pane to see the model terms, values of the coefficients, and goodness-of-fit statistics.

  • Optionally, in the Advanced Options section, specify coefficient starting values and constraint bounds, or change algorithm settings. The app calculates random start points for rational models, defined on the interval [0 1]. You can override the start points and specify your own values in the Fit Options pane.

For more information on the settings, see Specify Fit Options and Optimized Starting Points.

Selecting a Rational Fit at the Command Line

Specify the model type ratij, where i is the degree of the numerator polynomial and j is the degree of the denominator polynomial. For example, 'rat02', 'rat21' or 'rat55'.

For example, to load some data and fit a rational model:

load hahn1;
f = fit( temp, thermex, 'rat32')
plot(f,temp,thermex)

See Example: Rational Fit to fit this example interactively with various rational models.

If you want to modify fit options such as coefficient starting values and constraint bounds appropriate for your data, or change algorithm settings, see the table of additional properties with NonlinearLeastSquares on the fitoptions reference page.

Example: Rational Fit

This example fits thermal expansion data using a rational fit. The data describes the coefficient of thermal expansion for copper as a function of temperature in kelvin.

A rational fit is defined as the ratio of polynomials given by:

y=p1xn+p2xn1+...+pn+1xm+q1xm1+...+qm

where n is the degree of the numerator polynomial and m is the degree of the denominator polynomial. The rational equations are not associated with physical parameters of the data. Instead, they provide a simple and flexible empirical model that you can use for interpolation and extrapolation.

  1. Load the thermal expansion data in hahn1. The data set contains a vector of temperatures in kelvin (temp) and a vector of thermal expansion coefficients for copper (thermex).

    load hahn1
  2. Open the Curve Fitter app.

    curveFitter

    Alternatively, on the Apps tab, in the Math, Statistics and Optimization group, click Curve Fitter.

  3. In the Curve Fitter app, select curve data. On the Curve Fitter tab, in the Data section, click Select Data. In the Select Fitting Data dialog box, specify X Data as temp and Y Data as thermex. The Curve Fitter app fits and plots the curve data.

  4. Click the arrow in the Fit Type section to open the gallery, and click Rational in the Regression Models group.

  5. Try a quadratic/quadratic rational fit. In the Fit Options pane, select 2 for both Numerator degree and Denominator degree.

    Fit Options pane for rational fit with edited numerator and denominator degrees

  6. Rename the fit. In the Table Of Fits pane, double-click the Fit Name value and enter rat22.

  7. In the Visualization section, select Residuals Plot. Examine the data, fit, and residuals. Observe that the fit misses the data for the smallest and largest predictor values. Additionally, the residuals show a strong pattern for the entire data set. These observations indicate that a better fit is possible.

    Fit and residuals plot for quadratic/quadratic rational fit

  8. Try a cubic/cubic rational fit. First duplicate the current fit. On the Curve Fitter tab, in the File section, click Duplicate. Name the new fit rat33.

  9. In the Fit Options pane, select 3 for both Numerator degree and Denominator degree. Examine the data, fit, and residuals.

    Note

    Your results depend on random start points and might vary from those shown. The fit can exhibit discontinuities around the zeros of the denominator.

    Fit and residuals plot for cubic/cubic rational fit

  10. Look at the Results pane. The message and numerical results indicate that the fit did not converge.

    Results pane for cubic/cubic rational fit

    Although the message in the Results pane indicates that you might improve the fit if you increase the maximum number of iterations, a better choice at this stage of the fitting process is to use a different rational equation.

  11. Try a cubic/quadratic rational fit. First duplicate the current fit. On the Curve Fitter tab, in the File section, click Duplicate. Name the new fit rat32.

  12. In the Fit Options pane, select 3 and 2 for Numerator degree and Denominator degree, respectively.

  13. The data variables have very different scales, so select the Center and scale check box. The data, fit, and residuals are shown here.

    Fit and residuals plot for cubic/quadratic rational fit

    The fit behaves well over the entire data range, and the residuals are randomly scattered about zero. Therefore, you can confidently use this fit for further analysis.

See Also

Apps

Functions

Related Topics