I know some of you are into maple so I figured that perhaps someone might be able to help me with the issue that I am currently having.

Code:
restart; 
calcDistributionFunc := proc (f) 
    cdf := unapply(int(int(f(x)*sin(x), x = 0 .. x2), phi = 0 .. phi2), x2); 
    phi2 := 2*Pi; 
    
    cte := cdf((1/2)*Pi); 

    if 1 < evalf(cte) then 
        cte := 1/cte 
    end if; 

    cdf := apply(cdf, x); 
    cdf := cte*cdf; 
    cdf := unapply(cdf, x); 

    s := solve(y = cdf(x), x); 

    if 1 < nops([s]) then 
        b := unapply(s[1], y) 
    else 
        b := unapply(s, y) 
    end if 
end proc

calcDistributionFunc(cos(x));
The above code works fine as long as you do not put in into a procedure, from the moment I try to put the code into a procedure and call it using calcDistributionFunc(cos(x)); I get the error:

Error, (in solve) cannot solve expressions with int((cos(x))(x)*sin(x), x = 0 .. (1/2)*Pi) for x

For example a function f(x) = cos(x) will yield a distribution function: arccos(sqrt(-y+1))

In case you are wondering what it is that I am trying to do, I have a userdefined distribution function and I want to generate random numbers using this distribution by generating uniform random numbers between 0 and 1 and evaluating this random number using the calculated distribution function. This in turn is used for Monte Carlo based simulations...

Probably I am just missing some basic tips/pointers on how to use procedures in maple. I have to admit I am more a matlab person then a maple one, but I need an analytical solution and not a numerical one. I know that using Matlab I can also perform analytical math using the symbolic link toolbox, but that would be like driving around in a Porsche 959 trying to get to the finishline of Paris-Dakar.

Thanks in advance for any help .