avoid imaginary numbers in probabilistic calculation

Hello everyone,
I am trying to do create a number given its probability dencity function. So, for example I have h=expinv(mu), where expinv is the inverse exponential function and I get imaginary values of h. How can I avoid them?
Thanks in advance
Katerina

1 Comment

Dear all,
i am trying to run a Monte Carlo (MC) analysis in Matlab, so it is supposed that the probability is being provided automatically from the MC code that matlab has. What someone has to do at first is to determine the probability density functions of each parameter in order to get a sample of values from MC. In this point I have negative and even imaginary values which are undesirable. Do you know what to do in this case? Does anyone know aboout MC simulation in Matlab?
Regards, Katerina

Sign in to comment.

Answers (2)

You haven't told me how you got them, so I can't tell you how to avoid them. Most likely your calculations before calling expinv are returning complex numbers. Note that the first argument to expinv is a probability value, not the mean. The mean is the optional second input.
You have to provide both a probability value (0,1) and a value for mu for expinv. You are only giving it one parameter.

5 Comments

While I think this is part of the problem, I'm having a bit of a hard time generating purely imaginary results from expinv.
So if I pass in one argument that exceeds 1, it returns NaN.
expinv(12)
ans =
NaN
A single arg in the interval (0,1) returns a number, based on a default for the distribution parameter I assume.
expinv(.12)
ans =
0.12783
Negative (and solitary) inputs return NaN gain.
expinv(-.12)
ans =
NaN
Complex inputs? They yield complex outputs.
expinv(.12+i)
ans =
-0.28673 + 0.84914i
So while I think Star is essentially correct, I'm unsure what exactly the asker is doing. It looks like the asker is sending in complex input, and getting complex output.
The main point to take is to read the help for expinv, and make sure that you are passing what the software expects from the user. Otherwise, garbage in implies garbage out.
(Note to TMW: tools like this should have better error checking in a future release. One should not need to guess what has happened here. A friendly error message is part of writing GOOD, high quality software.)
I'm not sure where Star Strider came up with that. If you don't provide mu, it defaults to mu = 1. This is documented, and I can't see what it has to do with anything being complex.
>> expinv(0.7)
ans =
1.203972804325936
>> expinv(0.7,1)
ans =
1.203972804325936
Point is taken about error checking. This function should have issued an error with complex inputs saying that all inputs must be real. However, real inputs out of range returning NaN (meaning "undefined") is a normal behavior, not an error situation.
@ Mike — I didn’t see that in the expinv online documentation I cited. According to that, it requires both arguments. No default was mentioned for mu.
OK, I can definitely see how you got the idea now. In fact I don't think this default is very useful, which could explain why it isn't advertised that well, but it has been an explicit part of the implementation from function's inception, and the fact that mu=1 is the default has been documented in the "help expinv" text since a line to that effect was added in 2003. If you type "help expinv" you get
>> help expinv
expinv Inverse of the exponential cumulative distribution function.
X = expinv(P,MU) returns the inverse cdf of the exponential
distribution with mean parameter MU, evaluated at the values in P.
The size of X is the common size of the input arguments. A scalar input
functions as a constant matrix of the same size as the other input.
The default value for MU is 1.
[snip]
I agree that this is an oblique way of saying that you can get away with supplying only one input.
Returning to the OP's question, however, it doesn't matter how much code is in-between; Something the user is doing or not doing is causing complex inputs to be generated, and I still don't see how we have enough information to figure out what.
I haven’t used help since the Help browser appeared a few releases ago. It never occurred to me to look at help.
I agree with the rest.

Sign in to comment.

Categories

Find more on Signal Processing in Help Center and File Exchange

Asked:

on 8 Oct 2014

Commented:

on 8 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!