1

I am trying to place Weibull distributed random numbers in a sector of a circle.

I generated the random number, then distributed it in Weibull distribution. Now I want to use these Weibull distributed random numbers.

RadarSpace GetWeibullClutter()
{ 
    Random _randomNumberGenerator = new Random();
    Weibull myweibull = new Weibull(3,2,_randomNumberGenerator);

    int n = 50; // number of clutter elements
    var maxRange = _detectionModel.MaximumRange;
    var centreX = 0; // Centre of the field of view -- X coordinates
    var centreY = 0; // Centre of the field of view -- Y coordinates

    var minimumAngle = Math.PI / 4; // _detectionModel.MinimumPhi;
    var maximumAngle = (3 * Math.PI) / 4; // _detectionModel.MaximumPhir;

    var theta = (maximumAngle - minimumAngle) * myweibull + minimumAngle;
    var r = maxRange * Math.Sqrt(_randomNumberGenerator.Next(n));

    var x = centreX + r * Math.Cos(theta);
    var y = centreY + r * Math.Sin(theta);

I want the Weibull distributed random number to be multiplied in the var theta, but it rather says

operator '*' cannot be applied to opperands of type 'double' and 'weibull'

the updated code is

RadarSpace GetWeibullClutter()
            { 
                Random _randomNumberGenerator = new Random();
                Weibull myweibull = new Weibull(3,2,_randomNumberGenerator);

                int n = 50; // number of clutter elements
                var maxRange = _detectionModel.MaximumRange;
                var centreX = 0; // Centre of the field of view -- X coordinates
                var centreY = 0; // Centre of the field of view -- Y coordinates

                var minimumAngle = Math.PI / 4; // _detectionModel.MinimumPhi;
                var maximumAngle = (3 * Math.PI) / 4; // _detectionModel.MaximumPhir;

                var theta = 0.0;
                var r = 0.0;

                var randomNumbers = new double[n];
                myweibull.Samples(randomNumbers);
                for (int i = 0; i < n; i++)
                {
                    theta = (maximumAngle - minimumAngle) * randomNumbers[i] + minimumAngle;
                    r = maxRange * Math.Sqrt(randomNumbers[i]);
                }
                //var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
                //var r = maxRange * Math.Sqrt(_randomNumberGenerator.Next(n));

                var x = centreX + r * Math.Cos(theta);
                var y = centreY + r * Math.Sin(theta);
  • Where is the `Weibull` class coming from? Math.NET Numerics? – Sentry Jan 31 '19 at 10:09
  • i guess its fixed by `var time = (maximumAngle - minimumAngle) * myweibull.RandomSource.NextDouble() + minimumAngle;` but not sure. please let me know if it is the correct way or not? – Muhammad Shaheer Munir Jan 31 '19 at 10:17
  • @Sentry yes. i am using Math.Net – Muhammad Shaheer Munir Jan 31 '19 at 10:18
  • @Sentry can you pelase have a look once again? – Muhammad Shaheer Munir Jan 31 '19 at 11:14
  • Your updated code is fine syntactically, but without knowing what you want to calculate, it is hard to determine if it is correct. What should `time` and `r` represent? Are they independent variables? Are they both Weibull distributed? With the same parameters? – Sentry Jan 31 '19 at 11:33
  • @Sentry can you please have a look at the bottom of the page here: https://de.mathworks.com/matlabcentral/answers/90748-dividing-a-circle-into-equal-n-parts-and-then-generate-random-point-inside-each-part This is what i want to do in c# – Muhammad Shaheer Munir Jan 31 '19 at 12:08

1 Answers1

1

It looks like you're using the Math.NET Numerics library. The Weibull distribution class implements the IContinuousDistribution interface, which offers the properties and methods:

double Mode { get; }
double Minimum { get; }
double Maximum { get; }
double Density(double x);
double DensityLn(double x);
double Sample();
void Samples(double[] values);
IEnumerable<double> Samples();

Your variable myweibull contains an instance of the Weibull class, so you can't multiply it with a double.

You said that you generated the random number, but you didn't. For that, use the Sample() method:

var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;

This will give you one random number that is Weibull distributed. If you need more random numbers, either call Sample() repeatedly:

for( int i = 0; i < n; i++ )
{
    var theta = (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
    ...
}

or generate multiple random numbers at once using Samples()

var randomNumbers = new double[n];
myweilbull.Samples(randomNumbers);
for( int i = 0; i < n; i++ )
{
    var theta = (maximumAngle - minimumAngle) * randomNumbers[i] + minimumAngle;
    ...
}

Edit for the updated question

For your problem, r and theta must be independent, otherwise the angle and the radius will be completely correlated and all generated points are on a line.

for( int i = 0; i < n; i++ )
{
    var theta= (maximumAngle - minimumAngle) * myweibull.Sample() + minimumAngle;
    var r = maxRange * Math.Sqrt( myweibull.Sample() );

    var x = centreX + r * Math.Cos(theta);
    var y = centreY + r * Math.Sin(theta);

    // Do something with your generated point (x, y)
}

If you just generate 50 random values for theta and r but only calculate x and y once, you will only have one random point.

But I'm still wondering what you're trying to achieve, because the points won't be equally distributed in the sector, but Weibull distributed.

Sentry
  • 4,102
  • 2
  • 30
  • 38
  • ok. and what about the next line `var r = maxRange * Math.Sqrt(_randomNumberGenerator.Next(n));` as i want this to be also weibull distributed random. how can i replace `Next(n)` ? – Muhammad Shaheer Munir Jan 31 '19 at 10:33
  • You want `r` also to be Weibull distributed? Using the same Weibull distribution (with the same parameters)? Simply call `myweibull.Sample()` again – Sentry Jan 31 '19 at 10:34
  • yes i am using this in a loop to generate both as you said like ``` var randomNumbers = new double[n]; myweilbull.Samples(randomNumbers); for (int i = 0; i < n; i++) { var time = (maximumAngle - minimumAngle) * randomNumbers[i] + minimumAngle; var r = maxRange * Math.Sqrt(randomNumbers[i]); } ``` but now it says `The name ''Weibull'' doesnot exist in the current context` – Muhammad Shaheer Munir Jan 31 '19 at 10:41
  • @MuhammadShaheerMunir That sounds like you accidentally removed the import or similar. It is hard to read that code in a comment. Please either add the information to your question or (if it is a different problem) make a new question – Sentry Jan 31 '19 at 10:44
  • @MuhammadShaheerMunir Also, now you're using the **same** random number multiple times, which probably isn't what you want. Maybe you could clarify what you want to do in your question. – Sentry Jan 31 '19 at 10:45
  • could you please tell me if the problem of same random number is fixed in the updated code or not? – Muhammad Shaheer Munir Jan 31 '19 at 11:07
  • It is not fixed, you use the same number `randomNumbers[i]` multiple times. I suggest you generate them as you need them with `myweibull.Sample()`. But it really depends on **what you want** – Sentry Jan 31 '19 at 11:28
  • i want to create suppose 50 weibull random numbers within a sector of a circle as in https://de.mathworks.com/matlabcentral/answers/90748-dividing-a-circle-into-equal-n-parts-and-then-generate-random-point-inside-each-part please have a look at the bottom of the page that might can explain what i want to do. there is an image which can explain – Muhammad Shaheer Munir Jan 31 '19 at 11:35