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
Matrix Multiplication: The Matrix multiplication does not mean multiplying term by term; and it is not an array operation. The Matrix multiplication has a very particular mean

IS Functions for Strings: There are many functions for strings, that return logical true or false. The function isletter returns the logical true when the character is a lette

Function call: In the function call, not any arguments are passed so there are no input arguments in the function header. The function returns an output argument, therefore th

Algorithm for subfunction: The algorithm for subfunction askforn is as shown:  Prompt the user for the positive integer n.  Loop to print an error message and reprom

Data structures: The Data structures are variables which store more than one value. In order to made sense to store more than one value in a variable, the values must in some

Function fieldnames - structure functions: The function fieldnames will return the names of the fields which are contained in the structure variable. >> pack_fields = fiel

Algorithm for expfn function: The algorithm for expfn function is as shown:  receives the value of x as the input argument.  Prints the value of exp(x).  assigns a

Print from the structure: To print from the structure, a disp function will show either the whole structure or a field. >> disp(package) item_no: 123 cost: 19.99

Example to change the line width from the default: For illustration, to change the line width from the default of 0.5 to 1.5: >> set(hl,'LineWidth',1.5) As long as the

Illustration of initializing the data structure: illustration of initializing the data structure by preallocating is here as shown: >> cyls(3) = struct('code', 'c', 'dimen