2
$\begingroup$

Consider an interpolating function derived from some data, e.g.

data = Table[{x, Cos[2 π/1000 x] // N}, {x, -250, 250}];
fun[x_] = Piecewise[{{Interpolation[data][x], Min[data[[;; , 1]]] <= x <= Max[data[[;; , 1]]]}}]

As it is, the interpolation shows a hump that goes to zero at x=-250 and x=250:

Plot[fun[x], {x, -500, 500}]

enter image description here

Now I would like to change (manipulate) the interpolation function such that e.g. the function goes to zero at x=-100 and x=100 instead while the hight increases proportionally such as to keep the integral constant

Integrate[fun[x],{x,-Infinity,Infinity}]

318.31

Here a rough sketch how the result should look like enter image description here

How can I do this with mathematica?

EDIT:

Naively, I could always do

targetA = NIntegrate[fun[x], {x, -Infinity, Infinity}];
transfA = NIntegrate[fun[x 5/2.], {x, -Infinity, Infinity}];
newfun[x_] = fun[x 5/2] targetA/transfA;
Plot[{fun[x], newfun[x]}, {x, -500, 500}]

enter image description here

But I wonder if there is a less pedestrian way of doing that?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

The area under your curve is

Integrate[Cos[2 Pi/1000 x],{x,-250,250}]==1000/Pi

Scale your curve by a factor s

s=4;
Integrate[s*Cos[2 Pi/1000 x/s],{x,-250/s,250/s}]==1000/Pi

and that will hold for any positive value of s.

$\endgroup$
6
  • $\begingroup$ Note that Cos is chosen for convenience here, to illustrate the point. In actual application the data does not follow a known function. $\endgroup$
    – Kagaratsch
    Sep 12, 2019 at 4:20
  • 1
    $\begingroup$ For your unknown function does scaling down the horizontal extent by a factor of s and scaling up the vertical extent by a factor of s still yield the same area? For sufficiently nice functions that should be true. It might be amusing to try to find functions where that does not hold. $\endgroup$
    – Bill
    Sep 12, 2019 at 4:22
  • $\begingroup$ Oh, I see! That is a good point, I'll check. $\endgroup$
    – Kagaratsch
    Sep 12, 2019 at 4:23
  • $\begingroup$ Oh, in fact, $\int dx f(x)=a\int dy f(a y)$ for $x=ay$ makes total sense for anything smooth! You're right, my question is kind of silly, this should work most of the time (and indeed it works for the relevant data). $\endgroup$
    – Kagaratsch
    Sep 12, 2019 at 4:28
  • 1
    $\begingroup$ I want to be VERY clear. I was NOT being critical of you or your question or implying that it was in any way silly. We sometimes get so wrapped up in grinding through the calculus or through the programming that we sometimes miss the insight and understanding that lies hidden just below the surface. $\endgroup$
    – Bill
    Sep 12, 2019 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.