Simple matlab interpolation help

In summary, interpolation is a mathematical technique used to estimate values between known data points. In Matlab, interpolation can be performed using various methods such as linear, nearest neighbor, polynomial, spline, and piecewise polynomial interpolation. The "interp1" function in Matlab can be used to perform interpolation by taking in known data points and the desired method as inputs. Some common errors that may occur during interpolation include incorrect data input, choosing the wrong method, and insufficient data points. Interpolation can also be used for data with missing values, but the accuracy of the results may be affected. Other techniques, such as extrapolation or data imputation, may be used in such cases.
  • #1
JXPES
2
0
suppose I have a function f(x) which I know increases as x.

I'm trying to combine a for loop and if statement

x(1)=a;
x(2)=b;
x(3)=(a+b)/2;

for i=3:n
if f(x(i)) > A
x(i+1) = (x(i-2)+x(i))/2;
else
x(i+1) = (x(i-1)+x(i))/2
end
end

this method works for x(4), the rest come with errors! Am I missing something obvious? Thanks.
 
Physics news on Phys.org
  • #2
never mind. worked it out- the order of the intervals had to be considered
 

Related to Simple matlab interpolation help

What is interpolation and why is it important in Matlab?

Interpolation is a mathematical technique used to estimate values between known data points. In Matlab, interpolation is important because it allows for more precise and accurate analysis and prediction of data.

What are the different types of interpolation methods available in Matlab?

There are several interpolation methods available in Matlab, including linear, nearest neighbor, polynomial, spline, and piecewise polynomial interpolation. Each method has its own advantages and is suitable for different types of data.

How can I perform interpolation in Matlab?

To perform interpolation in Matlab, you can use the "interp1" function. This function takes in the known data points and the desired interpolation method as inputs, and outputs the estimated values at the desired data points.

What are the common errors encountered in interpolation using Matlab?

Some common errors in interpolation using Matlab include incorrect data input, choosing the wrong interpolation method for the data, and insufficient data points for accurate interpolation. It is important to carefully check the data and choose the appropriate method to avoid these errors.

Can interpolation be used for data with missing values?

Yes, interpolation can be used for data with missing values in Matlab. However, it is important to note that the accuracy of the interpolation results may be affected by the missing data points. In such cases, it is recommended to use other techniques, such as extrapolation or data imputation, to estimate the missing values.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
595
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
144
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top