Thread: Maple procedure issue

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    Maple procedure issue

    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 .

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Just looking at that error message, I would guess that

    Code:
    cdf := unapply(int(int(f(x)*sin(x), x = 0 .. x2), phi = 0 .. phi2), x2);
    should really be

    Code:
    cdf := unapply(int(int(f*sin(x), x = 0 .. x2), phi = 0 .. phi2), x2);
    since it seems to be dumping cos(x) in place of "f", not "f(x)"

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Wow, that I have been looking over this so many times... Thanks!

    Anyhow, I will have to move away from the analytical solution as finding the inverse of a function is not that straightforward anymore as soon as the function to be inverted gets quite complicated (which is the case as I am trying to fit functions to measured BSDF data).

    Seems I'm back where I started by performing my monte carlo simulations using distribution functions that are being sampled instead of using an analytical solution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. Hooked Procedure Early Return In/External Trigger
    By n00b3 in forum Windows Programming
    Replies: 4
    Last Post: 06-29-2008, 05:37 PM
  3. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  4. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  5. Collision with quads?
    By SyntaxBubble in forum Game Programming
    Replies: 6
    Last Post: 01-18-2002, 06:17 PM