forum.alglib.net

ALGLIB forum
It is currently Thu Mar 28, 2024 11:53 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Passing parameters to autogkintegrate in C#
PostPosted: Thu Nov 01, 2012 10:01 am 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
I need to pass 3 additional parameters to the autogkintegrate function using C#

I have tried following the recommendations in this thread:
viewtopic.php?f=2&t=386&p=1179&hilit=autogkintegrate+example
but I can't see how to get the values out of the obj object. The code in the thread used "double a_1 = (double)a.GetValue(0);" but GetValue is not recognised as a valid method by my compiler (VS 2010).

My code as it stands is:

Code:
       public static void int_function_1_func(double x, double xminusa, double bminusx, ref double res, object   obj)
        {
           // double r = obj(0);
           // double dna = obj(1);
           
            res = 40 * (1 - Math.Pow((1 - x / dna), 2)) * 2 * Math.Sqrt(r * r - Math.Pow(r - dna + x, 2));
        }
        public double  integrate(double[] parama)
        {
            object obj = parama ;

            double dna = parama[1];
            double a = 0;
            alglib.autogkstate s;
            double v;
            alglib.autogkreport rep;

            alglib.autogksmooth(a, dna, out s);
            alglib.autogkintegrate(s, int_function_1_func, obj );
            alglib.autogkresults(s, out v, out rep);

            return v ;
        }


The code is intended to link to Excel VBA, which it does if the parameters r and dna are replaced with values, so I just need to know how to pass the required values to the autogkintegrate function.

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Passing parameters to autogkintegrate in C#
PostPosted: Fri Nov 02, 2012 10:21 pm 
Offline

Joined: Sun May 16, 2010 11:42 pm
Posts: 63
Solved it! (or at least found a method that works).

Ref: http://msdn.microsoft.com/en-us/library/yz2be5wk(VS.80).aspx (boxing and unboxing):

Code:
int i = 123;
object o = (object)i;  // boxing


Code:
o = 123;
i = (int)o;  // unboxing


So my code is now:
Code:
     public static void int_function_1_func(double x, double xminusa, double bminusx, ref double res, object   obj)
        {
           double[] sectdims = (double[])obj;
           double r = sectdims[0];
           double dna = sectdims[1];
           double fcu = sectdims[2];
           
            res = fcu * (1 - Math.Pow((1 - x / dna), 2)) * 2 * Math.Sqrt(r * r - Math.Pow(r - dna + x, 2));
        }
        public double  integrate(double[] parama)
        {
            double dna = parama[1];
            Object obj = (object)parama ;

            double a = 0;
            alglib.autogkstate s;
            double v;
            alglib.autogkreport rep;

            alglib.autogksmooth(a, dna, out s);
            alglib.autogkintegrate(s, int_function_1_func, obj);
            alglib.autogkresults(s, out v, out rep);

            return v ;
        }


Which works!

My question now is, is this the best way, bearing in mind this comment from MS:
"In relation to simple assignments, boxing and unboxing are computationally expensive processes. When a value type is boxed, an entirely new object must be allocated and constructed. To a lesser degree, the cast required for unboxing is also expensive computationally. For more information, see Performance."?

_________________
Doug Jenkins
http://newtonexcelbach.wordpress.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 45 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group