Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

polyval in MATLAB: Syntax, Example and Reading delta

How MATLAB polyval works: syntax, a worked example, the polyfit-to-polyval workflow, reading delta, and coefficient order versus Octave and NumPy.

Written and maintained by CASRAI Editorial Board

Last updated

polyval in MATLAB evaluates a polynomial at the points you give it: y = polyval(coeffs,x) returns the value of the polynomial whose coefficients are in coeffs (highest power first) at every element of x. Used together with polyfit, it turns a fitted curve into predicted values, and its optional second output delta gives an error estimate for those predictions. This guide covers the syntax, a worked example, the fitted-model workflow and how to read delta correctly. It reflects the MathWorks documentation read on 2026-11-07.

What polyval is used for in research

Researchers use polyval to evaluate a polynomial: a calibration curve at new readings, a trend line at future time points, or a fitted model on a fine grid for plotting. The MathWorks Polynomials page describes a polynomial in MATLAB as a vector of coefficients in descending order, so [1 -4 4] represents x² − 4x + 4. polyval evaluates it, polyvalm evaluates a matrix polynomial, and polyfit finds the coefficients from data.

The polyval formula

For coeffs = [c1 c2 ... cn+1], polyval(coeffs,x) computes c1*x^n + c2*x^(n-1) + ... + cn*x + cn+1. The coefficient vector has length n+1 for a polynomial of degree n. It may be double or single, and complex values are allowed.

Install or access

polyval is a MATLAB function documented in the official MathWorks help at mathworks.com/help/matlab/ref/polyval.html. Get MATLAB from MathWorks; your institution’s site-licence administrator or the MathWorks website can tell you which access route applies to you. To confirm the function is available in your session, type help polyval or doc polyval at the command prompt.

Step-by-step: evaluate a polynomial and a fitted model

1. Evaluate a polynomial you already know

  1. Write the coefficients in descending powers: coeffs = [3 2 1]; represents 3x² + 2x + 1.
  2. Choose the query points: x = [5 7 9];
  3. Call the function: y = polyval(coeffs,x)

The MathWorks documentation shows this result: y = 86 162 262. You can check the first value by hand: 3·25 + 2·5 + 1 = 86. The output y has the same size as x.

2. Fit with polyfit, then evaluate with polyval

  1. Fit a degree-n polynomial: coeffs = polyfit(x,y,n);
  2. Build the points where you want predictions, for example xq = linspace(min(x),max(x),200);
  3. Evaluate: yfit = polyval(coeffs,xq);
  4. Plot the data and the curve together: plot(x,y,'o',xq,yfit,'-')

A simple check on a made-up data set: with x = [0 1 2 3] and y = [1 3 9 19] (exactly 2x² + 1), polyfit(x,y,2) returns coefficients close to [2 0 1] up to floating-point rounding, and polyval at x = 4 returns about 33.

3. Fit with normalisation (centerScale)

polyfit can return a third output, centerScale, when you request it. The documentation defines it as [mean(x) std(x)] when Normalize=true and as 0 and 1 when Normalize=false; requesting the third output makes Normalize=true the default. The fit is then done on the centred and scaled x, so you must pass centerScale back to polyval. The documented pattern is:

[coeffsNorm,~,centerScale] = polyfit(x,y,5,Normalize=true);
yfit = polyval(coeffsNorm,x,[],centerScale);

The empty [] is a placeholder for the fitStats argument, which sits in third position in the polyval call.

Syntax summary

Call Returns
y = polyval(coeffs,x) Polynomial values at x
[y,delta] = polyval(coeffs,x,fitStats) Values plus a standard-error estimate; fitStats comes from polyfit
y = polyval(coeffs,x,[],centerScale) Values when the fit used normalisation
[y,delta] = polyval(coeffs,x,fitStats,centerScale) Both of the above

Output and how to read it

y has the same size as x. delta, when requested, is the standard error for predicting a future observation and also has the same size as x. It is a prediction-interval quantity, not a confidence interval for the fitted line, so it is wider than the uncertainty of the curve itself. To get delta, call polyfit with the second output ([coeffs,fitStats] = polyfit(x,y,n)); fitStats is a structure with the fields R, df, normr and rsquared.

The documentation gives these readings:

  • For large samples, y ± Δ contains approximately 68% of future observations and y ± 2Δ approximately 95%.
  • If the coefficients come from a polyfit least-squares fit and the errors are independent, normally distributed and of constant variance, then y ± Δ contains at least 50% of future observations.

When you report results, state which of these conditions you checked. See assumptions of simple regression for residual checks and linear regression scatter plots for plotting the fitted line. For the predicted value symbol, see y hat (ŷ).

Troubleshooting

Wrong values: coefficient order

MATLAB expects descending powers. Passing [1 2 3] means x² + 2x + 3, not 1 + 2x + 3x². The order is the most common silent error when moving between tools; see the cross-walk in the table below.

Unstable or odd fits: ill-conditioning

The polyfit documentation states that an ill-conditioned fit can result from repeated or nearly repeated query points, or widely spaced query points, and advises adding distinct query points. It also notes that high-order fits have a large Vandermonde condition number and that Normalize=true can improve the numerical properties. If you normalise, remember to pass centerScale to polyval.

Matrix versus element-wise evaluation

polyval works element by element on x. To evaluate a polynomial with a square matrix as the argument, use polyvalm.

Rounding at high degree

Evaluation is subject to floating-point rounding; the NumPy documentation notes rounding error for high-degree polynomials in its Horner-scheme implementation. See IEEE 754 floating-point for background on why such errors arise.

Free alternatives and coefficient-order cross-walk

Tool Function Coefficient order Notes (from official docs)
MATLAB polyval(coeffs,x) Highest power first Optional delta output with fitStats; centerScale for normalised fits
GNU Octave polyval(p,x) Highest power first [y,dy] = polyval(p,x,s) with s from polyfit; y ± dy covers at least 50% of future predictions; polyval(p,x,[],mu) evaluates at (x − mu(1))/mu(2)
NumPy (legacy API) numpy.polyval(p,x) Highest degree first Documented as legacy; uses Horner’s scheme
NumPy (numpy.polynomial) numpy.polynomial package Lowest power first Preferred by NumPy for new code; mixing orders gives wrong results without an error

GNU Octave is free software; NumPy is open-source. Check each project’s own documentation for current installation routes.

Frequently asked questions

What does polyval do in MATLAB?

It evaluates a polynomial, given as a vector of coefficients in descending order, at each element of the input x and returns an array of the same size.

Is matlab polyval the same as polyfit?

No. polyfit(x,y,n) finds the coefficients of a degree-n least-squares polynomial; polyval uses coefficients to compute values. They are normally used as a pair.

What is a polyval example?

polyval([3 2 1],[5 7 9]) returns 86 162 262, the values of 3x² + 2x + 1 at 5, 7 and 9.

What is delta in polyval?

The standard error for predicting a future observation at each point of x. Roughly, y ± Δ is a 68% prediction interval for large samples and y ± 2Δ is 95%; with a polyfit fit and independent, normal, constant-variance errors, y ± Δ is at least a 50% interval.

Why is the third argument empty when I pass centerScale?

The third position is fitStats. Passing [] skips it while centerScale goes in fourth position.

Sources

Related reading on this site: MATLAB mod function and non-linear relationships.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about polyval in MATLAB: Syntax, Example and Reading delta

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →