Register to reply

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

by McLaren Rulez
Tags: array, data, function, interpolating, matlab
Share this thread:
McLaren Rulez
#1
Dec29-12, 09:21 AM
P: 261
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 :)
Phys.Org News Partner Science news on Phys.org
Scientists develop 'electronic nose' for rapid detection of C. diff infection
Why plants in the office make us more productive
Tesla Motors dealing as states play factory poker
rbj
#2
Dec29-12, 11:38 AM
P: 2,251
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]
McLaren Rulez
#3
Dec29-12, 11:47 AM
P: 261
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?


Register to reply

Related Discussions
Create function from a vector in matlab Math & Science Software 1
Create a function in MATLAB! Math & Science Software 4
How to create a verctor in matlab using data recorded in a text document? Math & Science Software 1
MATLAB find function 4D array Programming & Computer Science 3
Matlab - importing data from excel & interpolating Programming & Computer Science 1