Defining a test function $\phi\in\mathcal{D}(\mathbb{R})$ on Matlab

150 Views Asked by At

So the following, $\phi\in\mathcal{D}$, is an archetypal test function on $\mathbb{R}$:

$$\phi(x)=\begin{cases} \exp\left(-\frac{1}{1-x^{2}}\right),&\mbox{if }|x|<1, \\ 0,&\mbox{otherwise}. \end{cases}$$ I am having difficulty defining it, let alone plotting it on Matlab though. I used:

function y=test(x) y1=(exp(1/(1-x^2))).*abs(x)<1; y2=(0).*abs(x)>=1; y=y1+y2; end

Then attempted to plot with

x = -2:0.01:2; y=test(x); plot(x,y)

Only to receive the error message:

Error in test (line 2) y1=(exp(1/(1-x^2))).*abs(x)<1;

However, I cannot spot the problem and Matlab seems to indicate that my function definition is fine otherwise.

1

There are 1 best solutions below

5
On BEST ANSWER

We define x = -2:0.01:2. And now let's use the pre-defined Heaviside-function

Heaviside

to define a step function that is one between $-1$ and $1$; and zero otherwise. This is given by:

s = heaviside(x+1).*heaviside(-x)+heaviside(x).*heaviside(1-x)

Step

From here on we just need to multiply your $\phi$ by this step function $s$ to get the wanted result. So we avoid this distinction case pretty elegantly.

phi=(exp(-1./(1-x.^2))).*s

And plotting this gives via plot(x,phi)

test function

as we wanted.


Integration can be done as follows:

s = @(x)heaviside(x+1).*heaviside(-x)+heaviside(x).*heaviside(1-x); phi = @(x) exp(-1./(1-x.^2)).*s(x); d = @(t) integral(@(x)phi(x),0,t); fplot(d,[0,1])

Getting the following plot:

integral

It can be seen quiet nicely that for increasing $t$ the integral in not increasing as much as in the beginning.