Thread: Strange Pointers

  1. #1
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96

    Strange Pointers

    Hello Every1,
    I have problem with pointers in my code.
    I want to simulate the array according to the probabilities of the elements in the array.
    I am using GSL library for that.
    The syntax it uses is
    Code:
    gsl_ran_poisson (r, prob); // r is the envi setup ,prob is the probability for the Bernoulli trail
    I dont know how i should pass the probabilities from the arrays storing them.
    I have 3D arrays with values.


  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What data types are r and prob? Are they the pointers you're having problems with?

    Do you have a function prototype or definition for this? Any return type on this function?

    We need all the details!

  3. #3
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    r has nothing to do here, its just to set up environment for gsl lib.. (Random Number Distribution Examples - GNU Scientific Library -- Reference Manual)


    prob is floating value....

    it should return me array of integers0 and 1s)
    which it doesnt do

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by satty View Post
    r has nothing to do here, its just to set up environment for gsl lib.. (Random Number Distribution Examples - GNU Scientific Library -- Reference Manual)


    prob is floating value....

    it should return me array of integers0 and 1s)
    which it doesnt do
    Read the docs - it doesn't return an array of integers. You need to fill the array by calling the function in a loop...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    I meant r doesnt have anything to do with the issue i have....
    also i know i shd use for loop....
    dat anyway I am using....

    my question was how can i pass 3D array values to prob for gsl function

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by satty View Post
    I meant r doesnt have anything to do with the issue i have....
    also i know i shd use for loop....
    dat anyway I am using....

    my question was how can i pass 3D array values to prob for gsl function
    It's not entirely clear what you are trying to do. It sounds like you need to cycle through the array, passing each element as the second parameter of gsl_ran_poisson, storing the result somewhere, obviously. Anyway, it might help if you gave a more complete description of the problem...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    Code:
    for (i=0; i<iter; i++){
         for (j=0; j<nodes; j++){
           for (k=0; k<nodes; k++){
    	
          array2[i][j][k]=0;
        
          prob = array1[j][k];   ?????
         array2[i][j][k] = gsl_ran_bernoulli(r, prob);
    array1 has floating values, that i want to use as probabilites for my program.
    but it is a 2D array, i dont know how shd i pass it to prob....

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by satty View Post
    Code:
    for (i=0; i<iter; i++){
         for (j=0; j<nodes; j++){
           for (k=0; k<nodes; k++){
        
          array2[i][j][k]=0;
        
          prob = array1[j][k];   ?????
         array2[i][j][k] = gsl_ran_bernoulli(r, prob);
    array1 has floating values, that i want to use as probabilites for my program.
    but it is a 2D array, i dont know how shd i pass it to prob....
    Without knowing the exact implementation of your program, it's impossible to say. What do the arrays represent, and what is the significance of the dimensions being used?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    C++ Beginner !!!
    Join Date
    Jul 2010
    Posts
    96
    array1 just has values from a file which looks like this

    ## node1 node1 value
    n array 2 has to be one dimension higher than the array1 one because i want to iterate it for number of times...for bernouli trial

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by satty View Post
    array1 just has values from a file which looks like this

    ## node1 node1 value
    n array 2 has to be one dimension higher than the array1 one because i want to iterate it for number of times...for bernouli trial
    In that case, it seems like the code you posted may be the correct scheme. Not 100% sure, though. Have you run it to see if it gives satisfactory results?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  11. #11
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Post the prototype of gsl_ran_poisson() so it's clear what are its arguments and return values.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  2. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  3. pointers to arrays
    By rakeshkool27 in forum C Programming
    Replies: 1
    Last Post: 01-24-2010, 07:28 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM