Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Dec 29, 2012 #1
    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 :)
     
  2. jcsd
  3. Dec 29, 2012 #2

    rbj

    User Avatar

    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]
     
  4. Dec 29, 2012 #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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MATLAB help: Interpolating an array of data to create a function
Loading...