MATLAB help: Interpolating an array of data to create a function

In summary, the person is looking for a function that MATLAB can interpolate between points in an array to give a desired output.
  • #1
McLaren Rulez
292
3
Hi,

As the title suggests, I have a 2D array of data. Essentially, I solved a DE using MATLAB and it gave me the array of x against t. I want MATLAB to create a function for me by interpolation so I can use it again (to solve another different set of DEs). I've been stuck on this for a while now.

How do I go from an array of x vs t to the point where I have a function x(t)?

Thank you :)
 
Physics news on Phys.org
  • #2
polyfit()?

http://www.mathworks.com/help/matlab/ref/polyfit.html

the function x(t) will be a polynomial, so you may or may not like that.

you may want to choose another function basis, like adding up exponentials to fit your data. you might want to apply polyfit() to the logarithm of your data and then exponentiate the result. there is an unlimited number of methods to fit a deterministic function to given data.

another way of looking at it is that this [itex]x(t)[/itex] is ideally sampled (which means [itex]x(t)[/itex] was bandlimited before sampling) and the [itex]x[n][/itex] in the array are the samples. then you want to do bandlimited reconstruction. it might look like:

[tex] x(t) = \sum_{n==\infty}^{+\infty} x[n] \ \operatorname{sinc}((t - nT)/T) [/tex]

where

[tex] \operatorname{sinc}(u) = \frac{\sin(\pi u)}{\pi u} [/tex]
 
  • #3
Hi rbj,

Thanks for the reply. I did see polyfit but I was hoping for something slightly different. I didn't quite understand the last part of your post but I'm guessing it's a more advanced way of finding the equation of the best fit curve. The thing is, I don't need to know what this function is (it can be polynomial, exponential or anything).

I was hoping I could define a function f(t) such that if the argument is some t between my array points, MATLAB will do a linear interpolation and give me an output. I tried working with interp2 but I couldn't get what I want.

Once I do this, I think (please correct me if I am wrong) I can simply use this f(t) in the same way I use one of MATLAB's built in functions like sin(t) or exp(t) which are accepted by ode45 and other differential equation solvers. Is this possible?
 

1. How do I interpolate an array of data in MATLAB?

To interpolate an array of data in MATLAB, you can use the built-in function interp1. This function takes in the original array of data and the desired number of interpolation points and returns a new array with the interpolated values.

2. What is the purpose of interpolating an array of data?

The purpose of interpolating an array of data is to estimate values between the existing data points. This is useful when you have data points that are not evenly spaced, and you want to create a smooth function that can be used to make predictions or fill in missing data.

3. Can I choose the type of interpolation method to use in MATLAB?

Yes, the interp1 function in MATLAB allows you to specify the type of interpolation method to use, such as linear, nearest neighbor, spline, or cubic. This allows you to choose the method that best fits your data and the desired level of accuracy.

4. Can I visualize the interpolated function in MATLAB?

Yes, you can use the plot function in MATLAB to visualize the interpolated function. This will plot the original data points as well as the interpolated points, giving you a visual representation of the smooth function created from the interpolation.

5. Is it possible to interpolate data in higher dimensions in MATLAB?

Yes, MATLAB also has functions for interpolating data in higher dimensions, such as interp2 for 2D data and interp3 for 3D data. These functions work in a similar way to interp1 and allow for interpolation in multiple dimensions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
846
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
886
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
238
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top