0

I stumbled across this code which describes how you can construct smooth functions with compact support. Unfortunately, I'm not familiar with the programming language used so I can only guess what this code does.

Here's the the main code for convenience:

p = @(h) chebfun(1/h,[-h/2 h/2]);

f = p(1);
for k = 3:5
  f = conv(f,p(2^-k));
end

and

[a,b] = domain(f);
f1 = chebfun({0, f, 0},[-1 a b 2]);
f2 = chebfun({0, newDomain(f,[a+1,b+1]), 0}, [-1 a+1 b+1 2]);

Can somebody please explain/write down the mathematically what is happening here? Related to this question I asked a few days ago.

Any help is greatly appreciated.

Note: I know how convolution (which is what is happening here in general, right?) works mathematically, I just can't "translate this code to math".

ViktorStein
  • 4,838
  • 1
    $f$ is the convolution of several functions of the form $g(x) = \begin{cases}2^k & \text{if $x\in[-2^{-k-1},2^{-k-1}]$,} \ 0 & \text{otherwise}\end{cases}$. Related: Fabius function. –  Apr 19 '19 at 08:31
  • 1
    $\newcommand{\conv}{\operatorname{conv}}\newcommand{\chebfun}{\operatorname{chebfun}}\newcommand{\I}{\Bbb{I}}$If it helps at all, you can rewrite the for loop mathematically as $f_j = \conv\left(f_{j-1}, p\left(2^{-(j+2)}\right)\right)$, for $j=1,2,3$, and $f_0 = p_1$. (I just put $j=k-2$ to start the sequence of functions at $0$.) (We are told $p_h$ is a square wave of height $1/h$ and width $h$, i.e. $p_h(x) =\frac{1}{h} \I(-h/2\le x \le h/2)$.) So you are obtaining each $f_j$ by convolving the previous one with a twice higher and narrower $p$ function. It's possible you already knew this. – Minus One-Twelfth Apr 19 '19 at 08:31
  • 1
    Since convolutional $$ is associative, you can thus write $$\begin{align}f_3 &= f_2 p_{2^{-5}} \ &= f_1p_{2^{-4}} p_{2^{-5}} \ &= f_0* p_{2^{-3}}p_{2^{-4}} p_{2^{-5}} \ &= p_{1}* p_{2^{-3}}p_{2^{-4}} p_{2^{-5}}.\end{align}$$ – Minus One-Twelfth Apr 19 '19 at 08:39
  • Which parts of the code do you need help understanding... the function calls? You probably need to be more specific than just "translate this algorithm into a math equation for me" – Azmisov Apr 25 '19 at 18:17

1 Answers1

1

I will only answer about the second piece of code, since the comments already cover the first one.

The language used is MATLAB with the chebfun extension (check here for more infos ). The function chebfun just creates a function. The first input is the function declaration, e.g. '1/x' or 'sin(x)' and the second input defines the domain. Chebfun then evaluates the function not on a fixed grid as matlab would do but approximates the function using a different approach based on something the makers call "Chebyshev technology" (again check their website for detailed information). Now this second code looks different then the first on due to curly brackets, they define a pice wise function. Mathematically this means for $f_1$ $$ f_1(x) = \begin{cases} 0, & x \in [-1,a] \\ f(x), & x\in (a,b] \\ 0, & x\in (b,2] \end{cases} $$ similar thing then for $f_2$: $$ f_2(x) = \begin{cases} 0, & x \in [-1,a+1] \\ f(x-1), & x\in (a+1,b+1] \\ 0, & x\in (b+1,2] \end{cases} $$

This is a padding of f with zeros to be defined on the interval $[-1,2]$ for $f_1$ and $f_2$ padds $f(x-1)$ with zeros to be defined on the whole interval.

The code does not show what is done with $f_1,f_2$ afterwards.

ViktorStein
  • 4,838
TalBot
  • 111