# Scaling a part of a function without altering the rest of it

The question rises form the needing of plotting the function

\begin{equation} I\left(x, y\right) = I_0\operatorname{sinc}^2\left(x\right)\operatorname{sinc}^2\left(y\right). \end{equation} where \begin{equation} \operatorname{sinc}(x) = \begin{cases}\frac{\sin(\pi x)}{\pi x} &\text{ if } x \neq 0\, \\ 1 &\text{ if } x = 0 \end{cases} \end{equation} If you have already seen this function it's highly spiked at the origin of axes and decay very fast for values greater than 2 as you can see in the plot below Now I would like to give a nice representation of the function by scaling the central spike (or equivalently the rest of the function in order to make the hight of subsequent fringes of interference. Initially I thought to scale the plot in the circle around the origin which contains the central spike, but this does nor really work well since it changes the relative scale in a discontinuous way, which results in a bad behaviour in the plot So I thought that there could be a continuous function which can do the job I want, something for example like \begin{equation} {\rm scalingF}\left(x, y\right) \sim A\left(1-e^{-B\left(x^2 + y^2\right)}\right), \end{equation}

namely the positive opposite of a gaussian so that the outer part of the plot is stretched out more than the inner part, but unfortunately this method turns out in cutting the highest part, even if the rest of the plot is now precisely how I want it: \begin{equation} {\rm scalingF}\left(x, y\right) I\left(x, y\right) \end{equation} gives Does anybody know a way to scale just a part of this function maintaining it continuous and with a much more similar shape to the initial one (meaning that the profiles of the wave should remain the same)?

• Do you compute the scaling function yourself? If yes how? $1-e^{??}$ suffers from catastrophic cancellation for small arguments. If available use a function like expm1. – gammatester Jul 14 '18 at 13:53
• Have you tried plotting it on a logarithmic scale: $10\log_{10} I(x,y)$ ? – Andy Walls Jul 14 '18 at 14:14
• @gammatester I can't understand your question, but the function $$1-e^{-x^2}$$ is just a gaussian curve reflected along the x axis and shifted above of one, so no "catastrophic cancellation" occurs for me ;), but maybe I'm misunderstanding what you want to say! – opisthofulax Jul 14 '18 at 14:18
• If $x$ is small you have $1-e^{-x^2}=x^2-x^4/2$ but if you compute e.g. with IEEE double precision you have $e^{-x^2}\approx 1$, and the difference suffers from cancellation. But as Théophile has written, this is not your main problem. – gammatester Jul 14 '18 at 14:33

Your Gaussian idea is interesting; the reason it doesn't work is that the scaling function vanishes at $(0,0)$. To fix this, how about simply adding $1$:

$${\rm scalingF}\left(x, y\right) = A\left(1-e^{-B\left(x^2 + y^2\right)}\right) + 1$$

so that ${\rm scalingF}(0, 0) = 1$, and far enough from the origin, ${\rm scalingF}(x,y) \approx A + 1$.

Now, maybe you want to preserve the height everywhere except near the origin. In that case, we just scale down again (and I've used $A - 1$ as a multiplier instead of $A$ so that it's a bit cleaner):

$${\rm scalingF}\left(x, y\right) = \frac{(A-1)\left(1-e^{-B\left(x^2 + y^2\right)}\right) + 1}A$$

This will scale the origin to $1/A$ its original height while preserving the periphery.

• Thanks for your answer, but the problem of the gaussian curve is that augmenting $A$ will cause anyway to make appear a gaussian pattern on the top of the spike, if I try to zoom the outer region too much (for which I cannot change so much $B$ otherwise the effect of magnifying get lost). I'm thinking that I do not need a spiked curve but maybe something that has a plateau instead of the spike of the gaussian gurve and decreases similarly fast (in this case increase). – opisthofulax Jul 14 '18 at 14:54
• I managed a nice solution with arctan function, I'll post it right now ;) – opisthofulax Jul 14 '18 at 15:17
• @opisthofulax Interesting... glad you figured it out! – Théophile Jul 15 '18 at 3:10

So, I started considering that the gaussian curve is not precisely what I did need. In fact the scaling with this function tends to create an "inverse spike" in the function, rather than scaling with the same height all the point of a function in a certain circular/squared region. This behaviour can be easily visualised by plotting the suggested function from @Théophile with A and B parameters set in order to scale enough the whole graph except from the central spike: $$I\cdot{\rm scalingF}\left(x, y\right) = I\cdot\frac{(A-1)\left(1-e^{-B\left(x^2 + y^2\right)}\right) + 1}A$$ will produce (e.g for $A\gg1$, because I need a big scaling factor, and $B\approx.1$ as I just need a small region centered around the origin) That's because it's scaling the center to $1/A$, but the stuff around is not scaled the same nor less, but more.

Then a function which stays the same for and interval and then grows really fast is needed. Plus, the region not around the axes (the blackest ones) must be scaled more than the region along the axes. Now, by knowing that a $\operatorname{rect}(x)$ function will create a bad discontinuity (the first solution tried by me), I thought that the nicest solution was a "continuous" $\operatorname{rect}(x)$ function, which can easily be obtained by thinking as the sum of two $\arctan(x)$ functions "going in opposite directions" in which the arguments of $\arctan(x)$ has been choosen for cutting intensity in the region $\approx[-3.5, 3.5]$ which is more or less the one in which the original function is having that big spike. At is point there are two possibilities. The first is to multiply the two "$\operatorname{rectarctan}(x)$" in order to get a distribution of intensity \begin{equation} {\rm scalingF1}\left(x, y\right) = \arctan[5 x - 20] - \arctan[5 x + 20] + 1.01 \pi)\cdot (\arctan[5 y - 20] - \arctan[5 y + 20] + 1.01 \pi) \end{equation} where the factor of pies control the proportion between the central spike and the rest of the scaled graph such as if they become too big the scaling quantity on the central spike will become greater than the one on the other part.

Anyway, as it clear to see from figure 3 the path along the axis is not stretched out, so it can be annoying to have the spikes far from the axes bigger than the one along the axes as you can see below But a simple modification is possible in order to remedy this little bug, by substituting the multiplication in the scaling function by the sum \begin{equation} {\rm scalingF2}\left(x, y\right) = \arctan[5 x - 20] - \arctan[5 x + 20] + 1.01 \pi)\cdot (\arctan[5 y - 20] - \arctan[5 y + 20] + 1.01 \pi) \end{equation} which graph is This function modulates both contents along the axes and contents outside, by cutting high intensities in the center, as it's possible to see in the final output 