How to compute the *numerical values* of a chebfun on a Chebyshev grid?

49 views
Skip to first unread message

Paul Rapine

unread,
Jul 13, 2022, 9:04:30 AM7/13/22
to chebfun-users
Hello everyone,

I am new to the board, and relatively new to Chebfun, so apologies if this has been answered somewhere else or is in the manual (I am not able to find it myself there).

My issue is how to obtain the numerical values of a Chebfun at the Chebyshev points. I understand that this was possible before Version 5. How do I compute these numerical values?

I thought that using simple matrix expressions using the coefficients of the Chebyshev representation I would be able to obtain them, but the results are way off the type of fit one "sees" from the use of the "plot" command.

Anyone can help? Thanks in advance, Paolo

Nick Hale

unread,
Jul 13, 2022, 10:03:05 AM7/13/22
to chebfun-users
Hi Paulo

I think   get(f, 'values') is what you are looking for?

>> f = chebfun(@(x) exp(x))
f =
   chebfun column (1 smooth piece)
       interval       length     endpoint values  
[      -1,       1]       15      0.37      2.7
vertical scale = 2.7
>> get(f, 'values')
ans =
    0.3679
    0.3772
    0.4062
    0.4576
    0.5361
    0.6480
    0.8005
    1.0000
    1.2492
    1.5432
    1.8654
    2.1855
    2.4620
    2.6510
    2.7183

Best regards

Nick

Nick Trefethen

unread,
Jul 13, 2022, 10:09:09 AM7/13/22
to chebfun-users
And here's another approach (equivalent mathematically, but not identical in terms of rounding errors):

>> f = chebfun(@(x) exp(x));
>> v1 = get(f,'values');
>> v2 = f(chebpts(length(f)));
>> norm(v1-v2)
ans = 1.8519e-15

Paul Rapine

unread,
Jul 14, 2022, 5:16:46 AM7/14/22
to chebfun-users
Apologies for answering late but I am a technological cretin and the automatic link with my email box was not set up.

Thank you very very much for your help in this.

Your answers are exactly what I was looking for.

And I got answered from *the* Trefethen himself! Red letter day!

Thank you so much and if in the UK, enjoy the sunny weather!
Reply all
Reply to author
Forward
0 new messages