convert array (column vector) to chebfun

154 views
Skip to first unread message

Edgar Avalos

unread,
May 5, 2021, 4:20:48 AM5/5/21
to chebfun-users
Hi everyone,
Probably this is simple but can't figure out how to convert a numerical array into a chebfun. Specifically a  nx1 double.  So, if I have a column vector v of n elements, how can I convert this into a chebfun? I would like to be able to do something like:

dom = [-1 1];

vCheb=chebfun(@(x) v); % v is a result from another calculation in matlab.


Domain of v is [-1 1], but discretization is not spectral but just simple equally spaced intervals.

Any idea?

Edgar


Nick Hale

unread,
May 5, 2021, 6:52:44 AM5/5/21
to chebfun-users
Hi Edgar

There are a number of ways, which I list below.

The first uses the 'equi' flag, which tells Chebfun to use a 
certain rational interpolant through the (assumed) equally
spaced data.

The second uses polynomial interpolation through equally
spaced points (which is usually a bad idea).

The third uses cubic splines. The downside here is that 
the interpolant is not global (and convergence will probably
be slower than 'equi' as n increases).

n = 9;
t = linspace(-1,1,n)';
v = 1./(1+25*t.^2);
plot(t, v, '.', 'markersize', 20), hold on
f = chebfun(v, 'equi'); plot(f)
g = chebfun.interp1(t,v); plot(g), 
h = chebfun.spline(t, v); plot(h), 
hold off

Capture.PNG
Reply all
Reply to author
Forward
0 new messages