I'm trying to obtain the distribution of the magnitude (length) of the vectorial sum of two vectors under a random (uniformly distributed) angle $\phi$. The sum is $\sqrt{x^2+y^2+2xy\cos(\phi)}$, where $x$ and $y$ are the lengths of the two vectors.

This is my code:

ModelTest = NormalDistribution[10, 5];
TailExp = ExponentialDistribution[0.2];
Sumf[x_, y_, phi_] = Sqrt[x*x + y*y + 2*x*y*Cos[phi]];
Trafo = TransformedDistribution[
  Sumf[x, y, z], {
    x \[Distributed] ModelTest, 
    y \[Distributed] TailExp, 
    z \[Distributed] UniformDistribution[{0, Pi}] 

However, evaluating Trafo for a single point fails:

PDF[Trafo, x][5]

does not evaluate to a number.

I am rather new to Mathematica, so it's not clear to me whether there is a problem in my code or my approach in general?

Edit (on request I am adding more information on the final goal for which this setup is a mock-up):

I have a measured distribution of a physical quantity which I assume to be the vectorial sum of two random components. For one component (the bulk at low values) I have an analytical model. Now I need to find the other distribution (that is dominant in the tail). Unfortunately, it is not obvious what distribution that would be. (It is certainly not exponential because that is too steep, but it seemed to be simplest to use for the mock-up.) In the end I need to do a fit to determine the parameters of the tail distribution.

My intention was to use Mathematica to try a few different distributions for the tail to see what the overall distribution looks like and if it resembles the measurement. However, it seems to be simpler (and resonably fast) doing a naive numerical convolution instead.

  • 1
    $\begingroup$ Shouldn't it be PDF[Trafo, 5] ? $\endgroup$
    – chris
    Feb 15, 2015 at 14:38
  • $\begingroup$ I did try Summe = PDF[Trafo, x]; Summe2[5] (that's what I had originally) and PDF[Trafo,5], but none of them works. $\endgroup$ Feb 15, 2015 at 14:56
  • $\begingroup$ @fuenfundachtzig first part is certainly wrong. The latter ought to work unless Mathematica can't handle this configuration (TransformedDistribution fails on many of the less trivial transforms). $\endgroup$ Feb 15, 2015 at 22:27
  • $\begingroup$ @SjoerdC.deVries: What do you mean by first part? Summe = PDF[Trafo, x]; Summe[5]? (Note that there is a typo in my previous comment. You don't mean that, do you?) $\endgroup$ Feb 16, 2015 at 9:23
  • $\begingroup$ @fuenfundachtzig I was referring to your comment and I noticed the typo, but that's not what I meant. your calculation boils down to PDF[Trafo, x][5] and that is incorrect. You want to have the PDF of trafo evaluated at x=5. That's done by PDF[Trafo, 5] as Chris said or by PDF[Trafo][5] and not by PDF[Trafo, x][5]. $\endgroup$ Feb 16, 2015 at 15:23

1 Answer 1


In order to get a feeling about what is going on here I suggest to perform a simulation.


rx := RandomVariate[NormalDistribution[10, 5]];
ry := RandomVariate[ExponentialDistribution[0.2]];
rphi := \[Pi] Random[];

be the simulated variables, and

s := Module[{x = rx, y = ry, phi = rphi}, Sqrt[x^2 + y^2 + 2*x*y*Cos[phi]]];

the function whose distribution we are looking for.

Let's now calculate a sample of 10^5 numbers s:

ss = Array[s &, 10^5];

The histogram of ss gives the requested distribution

(* 150216 _Histogram.jpg)

enter image description here

The resulting distribution resembles a Gamma Distribution.

Remark 1: I tried to perform the transformation analytically, and failed even for just one variable of the three. But this path should be followed more closely.

  • $\begingroup$ Hm. Why would there be imaginary values for s? The argument of the sqrt function is always non-negative. $\endgroup$ Feb 16, 2015 at 9:21
  • $\begingroup$ Oh, I see one potential problem. Both x and y should be cutoff at 0 (i.e. also non-negative). How do I do that (for x)? But still, s should be non-negative even if x becomes negative... $\endgroup$ Feb 16, 2015 at 9:27
  • $\begingroup$ Oh, I made a mistake. I'll correct it immediately. $\endgroup$ Feb 16, 2015 at 11:14
  • $\begingroup$ @fuenfundachtzig: you were right, hundertprozentig! ;-) $\endgroup$ Feb 16, 2015 at 11:42
  • $\begingroup$ ;) Any other ideas? $\endgroup$ Feb 16, 2015 at 16:56

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.