1
$\begingroup$

I was wondering if it is possible to create a function $f(x)$ in matlab based on $y$ values.

Example

$X=[0,1,2,3,4,5,6,7,8,9]$

$Y=[5,6,7,8,9,10,11,12,13,14]$

In this trivial example I wish to get $f(x)=x+5$.

If my memory serves me well, I remember that maple provide such capability. Wonder if this can be done in matlab?

Thanks

  • 1
    (If you're just trying to find a fit for some data, not necessarily in Matlab, try http://zunzun.com/FunctionFinder/2/ )2011-10-07

1 Answers 1

2

polyfit(X,Y,n) will give you the coefficients of n'th degree polynomial that fits best to your data (in SSE sense). For your example:

  >> X=[0,1,2,3,4,5,6,7,8,9];  >> Y=[5,6,7,8,9,10,11,12,13,14];  >> polyfit(X,Y,1)  ans =      1.0000    5.0000