A simple polynomial construction about chebfun

99 views
Skip to first unread message

hejun Huang

unread,
Feb 26, 2021, 1:57:45 AM2/26/21
to chebfun-users

Hello Chebfun friends!

I have a very simple question but since I could not figure out after searching a lot, I have to bother you.

The core idea of the Chebyshev approximation is: $\sum^{N}_{i=0}{C_i \times T_i} = P_N \approx f(x)$, where f(x) is the target function. Now suppose the f is an non-polynomial function.

And now we want to represent the polynomial function directly to do sum-of-squares optimization via chebfun-toolbox, like f = chebfun('sqrt(sqrt((exp(x)*cos(x))^2))',[-1,1],'splitting','on'). Clearly, f is chebfun-structure data. 

(1) We can obtain the coefficients C by chebcoeffs(f),;

(2) Suppose the truncation degree is 20, we can obtain the Chebshev polynomials T by chebpoly(20,[0,4]).

Till now, I get confused for the next process. What I want is an univariate polynomials functions with clear coefficients as this form: $\sum^{N}_{i=0}{C_i \times T_i} = P_N \approx f(x)$. And I believe the clear guys designed chebfun-toolbox must consider it. But I just don't know how to figure it. Can anyone help?

I look forward to hearing from you soon! Thanks in advance!

Hejun Huang     Chinese University of Hong Kong

Nick Hale

unread,
Feb 26, 2021, 2:10:40 AM2/26/21
to chebfun-users
You can construct a degree 20 interpolant to the given function with
>> f = chebfun('sqrt(sqrt((exp(x)*cos(x))^2))',[-1,1], 20)
f =
   chebfun column (1 smooth piece)
       interval       length     endpoint values  
[      -1,       1]       20      0.45      1.2 
vertical scale = 1.2 

Alternatively you can construct the degree 20 truncated Chebyshev series with
>> g = chebfun('sqrt(sqrt((exp(x)*cos(x))^2))',[-1,1], 'trunc', 20)
g =
   chebfun column (1 smooth piece)
       interval       length     endpoint values  
[      -1,       1]       20      0.45      1.2 
vertical scale = 1.2 

Note that these are not the same thing:
>> norm(f-g)
ans =
   2.5011e-11

For more details see >> help chebfun or the Chebfun Guide.

hejun Huang

unread,
Feb 27, 2021, 2:08:22 AM2/27/21
to chebfun-users
Hi, Professor Nick. Thanks for your reply. I have fixed my questions before. But again I met another really weird question in approximation via Chebfun, the code has shown in figure 1.
>> For  convenience, I have attached the original code at the post end. 
check.png
And the result of the polynomial approximation is not accessible as figure 2.
check2.png
>> The green and black line has perfect approximation performance, while the red line seems a disaster.

I have followed the Chebfun-guide but still not figure it out. Really appreciate for your suggestions if available!
Thanks advanced!

Jun 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
clear;clf;clc;

%% Preliminaries
syms x;
deg = 5; % Series degree
% Non-polynomial to polynomial via chebyshev approximation 
f1 = chebfun('sqrt(sqrt((exp(x)*cos(x))^2))-1',[0,4],'splitting','on');
% Construct the compare approximation degree
[f2,e2] = minimax(f1,deg);

%% Construct the polynomials
C = transpose(flip(chebcoeffs(f2,deg+1))); % Obtain the coefficients of $T_n$
A = poly(chebpoly(deg,[0,4])); % Obtain the coefficients of polynomials
X = transpose(flip(monomials(x,0:deg))); % Create the polynomials
ft = A.*X; % Construct the $T_n$
k = sum(C.*ft); % Construct the $P_n = \sum^{6}_{i=1}C(i)*T(i)  

%% Plot
plot(f1,'g',f2,'k');
hold on; grid on;
fplot(k,'r',[0,4]);
title('$$\sqrt{\vert \exp{(x)} \times \cos{(x)} \vert}-1$$','interpreter','latex');
legend('Chebfun approximation','Chebfun approximation of degree 5','Polynomial approximation of degree 5')

Reply all
Reply to author
Forward
Message has been deleted
0 new messages