Example of interpolation and extrapolation, MATLAB in Engineering

Example of Interpolation and extrapolation:

The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the particular degree which best fits the data by using a least squares algorithm. There are 3 arguments passed to the function: the vectors which represent the data, and the degree of the preferred polynomial. For illustration, to fit a straight line (degree 1) through the earlier data points, the call to the polyfit function would be:

>> polyfit(x,y,1)

ans =

   0.0000 67.6000

that says that the best straight line is of the form 0x + 67.6. Though, from the plot as shown in figure, it appears like a quadratic would be a much better fit. The following would generate the vectors and then fit a polynomial of degree 2 through the data points, storing the values in a vector known as coefs.

636_Example of Interpolation and extrapolation.png

>> x = 2:6;

>> y = [65 67 72 71 63];

>> coefs = polyfit(x,y,2)

coefs =

   -1.8571 14.8571 41.6000

This says that the MATLAB has determined that the best quadratic which fits these data points are:

-1.8571x2  + 14.8571x + 41.6. So, the variable coefs now stores a vector which represents this polynomial.

Posted Date: 10/22/2012 8:45:55 AM | Location : United States







Related Discussions:- Example of interpolation and extrapolation, Assignment Help, Ask Question on Example of interpolation and extrapolation, Get Answer, Expert's Help, Example of interpolation and extrapolation Discussions

Write discussion on Example of interpolation and extrapolation
Your posts are moderated
Related Questions
Displaying the cell arrays: There are several techniques of displaying the cell arrays. The celldisp function shows all elements of the cell array:   >> celldisp(cellro

Executing a program: Running the program would be completed by typing the name of the script; this would call the other functions: >> calcandprintarea Whenever prompt

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

Example of Menu driven modular program: As an illustration of such a menu-driven program, we will write a program to discover the constant e. The constant e, known as the n

Solving 2 × 2 systems of equations: However this may be easy in a MATLAB, in normal finding solutions to the systems of equations is not. The systems which are 2 × 2 are, thou

A matlab function to calculate filter order

Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

Initializing the data structure - Function: Function is shown as:   >> printcylvols(cyls) Cylinder x has a volume of 169.6 Cylinder a has a volume of 100.5

Symbolic Variables and expressions: The MATLAB has a type known as sym for the symbolic variables and expressions; these work with strings. The illustration, to generate a sym

deblank function: The deblank function eliminates only trailing blanks from the string, not leading the blanks. The strtrim function will eliminate both the leading and traili