Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > N-dimensional mathematical functions

Reply
Thread Tools

N-dimensional mathematical functions

 
 
jacek.strzelczyk@gmail.com
Guest
Posts: n/a
 
      02-18-2008
Hello,

I'm looking for a C library that provides the notation of n-
dimensional mathematical functions. Or is there any other way to
decode that kind of functions in C language?

Thanks in advance,
Jacek
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      02-18-2008
On Feb 18, 7:38*am, jacek.strzelc...@gmail.com wrote:
> Hello,
>
> I'm looking for a C library that provides the notation of n-
> dimensional mathematical functions. Or is there any other way to
> decode that kind of functions in C language?


In C, we just code a vector as an array.
Sample C vector code for differential equations is found here for
cvode.tar.gz:
http://www.netlib.org/ode/
 
Reply With Quote
 
 
 
 
jacek.strzelczyk@gmail.com
Guest
Posts: n/a
 
      02-19-2008
On 19 Lut, 00:11, user923005 <dcor...@connx.com> wrote:
> On Feb 18, 7:38 am, jacek.strzelc...@gmail.com wrote:
>
> > Hello,

>
> > I'm looking for a C library that provides the notation of n-
> > dimensional mathematical functions. Or is there any other way to
> > decode that kind of functions in C language?

>
> In C, we just code a vector as an array.
> Sample C vector code for differential equations is found here for
> cvode.tar.gz:http://www.netlib.org/ode/


But vector is not enough to note all kinds of functions. For example
f(x)=1/x is not in polynomial form, so you can't describe it by simple
vector. Is there any other, more sophisticated way?
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      02-19-2008
wrote:

> But vector is not enough to note all kinds of functions. For example
> f(x)=1/x is not in polynomial form,


-1 is a perfectly good exponent. I presume I'm missing something.

--
"Well begun is half done." - Proverb

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-19-2008
writes:

> On 19 Lut, 00:11, user923005 <dcor...@connx.com> wrote:
>> On Feb 18, 7:38 am, jacek.strzelc...@gmail.com wrote:
>>
>> > Hello,

>>
>> > I'm looking for a C library that provides the notation of n-
>> > dimensional mathematical functions. Or is there any other way to
>> > decode that kind of functions in C language?

>>
>> In C, we just code a vector as an array.
>> Sample C vector code for differential equations is found here for
>> cvode.tar.gz:http://www.netlib.org/ode/

>
> But vector is not enough to note all kinds of functions. For example
> f(x)=1/x is not in polynomial form, so you can't describe it by simple
> vector. Is there any other, more sophisticated way?


comp.programming may be better. I, for one, was not replying simply
because all the questions I had about what you need are not C
questions. Anyway, to get further it would be better to know an
example of the kind of thing you need the library to do, together with
some idea of the range ("I need to work for all piece-wise continuous
functions of n variables"). The example makes it concrete, the range
says what can and can not be ignored. "Decode" and "n-dimensional"
are very broad (and to me, at least, the dimension of a function is a
very specific thing that crops up only in fractal geometry).

--
Ben.
 
Reply With Quote
 
jacek.strzelczyk@gmail.com
Guest
Posts: n/a
 
      02-19-2008
On 19 Lut, 12:48, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> jacek.strzelc...@gmail.com writes:
> > On 19 Lut, 00:11, user923005 <dcor...@connx.com> wrote:
> >> On Feb 18, 7:38 am, jacek.strzelc...@gmail.com wrote:

>
> >> > Hello,

>
> >> > I'm looking for a C library that provides the notation of n-
> >> > dimensional mathematical functions. Or is there any other way to
> >> > decode that kind of functions in C language?

>
> >> In C, we just code a vector as an array.
> >> Sample C vector code for differential equations is found here for
> >> cvode.tar.gz:http://www.netlib.org/ode/

>
> > But vector is not enough to note all kinds of functions. For example
> > f(x)=1/x is not in polynomial form, so you can't describe it by simple
> > vector. Is there any other, more sophisticated way?

>
> comp.programming may be better. I, for one, was not replying simply
> because all the questions I had about what you need are not C
> questions. Anyway, to get further it would be better to know an
> example of the kind of thing you need the library to do, together with
> some idea of the range ("I need to work for all piece-wise continuous
> functions of n variables"). The example makes it concrete, the range
> says what can and can not be ignored. "Decode" and "n-dimensional"
> are very broad (and to me, at least, the dimension of a function is a
> very specific thing that crops up only in fractal geometry).
>
> --
> Ben.



Ok, you're right. So example:
I want to create a library function that will use Monte Carlo methods
to find a minimum of given mathematical function. The application
programmer that wants to use this library feature need to pass given
mathematical function to the library in some way. For example, the
function can be:
f(x1,x2) = 2*pi^2 / 3*(x1+x2)^3 + x1*x2
So, to find its minimum the programmer has to call library function
'minimum' and pass the f(x1,x2) function.
My question is: how can that kind of function be decoded in C
language? In my opinion using just an array is not enough.
I simply need to calculate function value for some random arguments in
program.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-19-2008
wrote:
>
> Ok, you're right. So example:
> I want to create a library function that will use Monte Carlo methods
> to find a minimum of given mathematical function. The application
> programmer that wants to use this library feature need to pass given
> mathematical function to the library in some way. For example, the
> function can be:
> f(x1,x2) = 2*pi^2 / 3*(x1+x2)^3 + x1*x2
> So, to find its minimum the programmer has to call library function
> 'minimum' and pass the f(x1,x2) function.
> My question is: how can that kind of function be decoded in C
> language? In my opinion using just an array is not enough.
> I simply need to calculate function value for some random arguments in
> program.


The magic phrase is "function pointer."

double func(double x1, double x2)
{
return 19.739208802178717237668981999752
/ (3 * (x1+x2)*(x1+x2)*(x1+x2))
+ x1 * x2;
}

result_type minimize(various_params,
double (*fptr)(double,double),
more_params)
{
...
z = fptr(x, y);
...
}

...
result = minimize(params, func, other_params);

--



 
Reply With Quote
 
jacek.strzelczyk@gmail.com
Guest
Posts: n/a
 
      02-19-2008
> The magic phrase is "function pointer."
>
> double func(double x1, double x2)
> {
> return 19.739208802178717237668981999752
> / (3 * (x1+x2)*(x1+x2)*(x1+x2))
> + x1 * x2;
> }
>
> result_type minimize(various_params,
> double (*fptr)(double,double),
> more_params)
> {
> ...
> z = fptr(x, y);
> ...
> }
>
> ...
> result = minimize(params, func, other_params);
>
> --
> Eric.Sos...@sun.com


Ok, this is some solution. But in this case, the function has to be
directly programmed by programmer. What if user would type the
function and then the input would be parsed by some parser. How can
the function can be coded then?
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-19-2008
writes:
>> The magic phrase is "function pointer."
>>
>> double func(double x1, double x2)
>> {
>> return 19.739208802178717237668981999752
>> / (3 * (x1+x2)*(x1+x2)*(x1+x2))
>> + x1 * x2;
>> }
>>
>> result_type minimize(various_params,
>> double (*fptr)(double,double),
>> more_params)
>> {
>> ...
>> z = fptr(x, y);
>> ...
>> }
>>
>> ...
>> result = minimize(params, func, other_params);


The above was written by Eric Sosman. Google Groups automaticalloy
inserts an attribution line for quoted material, a line of the form
"So-and-so writes:". Please don't delete that line; it makes it
easier to follow the discussion.

> Ok, this is some solution. But in this case, the function has to be
> directly programmed by programmer. What if user would type the
> function and then the input would be parsed by some parser. How can
> the function can be coded then?


The only pure C solution I can think of is to write your own
expression parser that produces a (mostly binary) tree representing
the mathematical function. You can then have a C function, perhaps
called "evaluate", that takes a pointer to the root of the tree and
the values of x1 and x2, and returns the result of evaluating the
mathematical function with those arguments.

It's going to be substantially slower than using a C function
directly; this may or may not matter. It's also going to be
substantially mor work; you'd essentially be doing part of what the
compiler normally does.

Consider that some other languages provide features that could make
this easier. For example, Perl's built-in "eval" function can
directly execute a chunk of Perl code passed as a string. The various
Lisp-like languages provide similar facilities.

Or you could take a C representation of the mathematical function as
input and automatically generate a C source file that you then compile
and execute.

--
Keith Thompson (The_Other_Keith) <kst->
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-19-2008
wrote:
>> The magic phrase is "function pointer."
>>
>> double func(double x1, double x2)
>> {
>> return 19.739208802178717237668981999752
>> / (3 * (x1+x2)*(x1+x2)*(x1+x2))
>> + x1 * x2;
>> }
>>
>> result_type minimize(various_params,
>> double (*fptr)(double,double),
>> more_params)
>> {
>> ...
>> z = fptr(x, y);
>> ...
>> }
>>
>> ...
>> result = minimize(params, func, other_params);

>
> Ok, this is some solution. But in this case, the function has to be
> directly programmed by programmer. What if user would type the
> function and then the input would be parsed by some parser. How can
> the function can be coded then?


Parse the user's input, "compile" it into an interpreted
"instruction set" of your own devising, and run your own
interpreter on it each time you need a new value. There's
nothing particularly C-specific about this stuff.

--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lacking in mathematical functions Takeshi NISHIMATSU Ruby 0 05-06-2009 06:42 AM
Rowfilters Mathematical Representation thecameleon06@hotmail.com ASP .Net 0 11-14-2005 08:52 AM
accuracy of mathematical functions Thomas Lumley C Programming 6 07-06-2005 12:59 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM
Mathematical Operations in VHDL MtnSurf8 VHDL 1 04-25-2004 06:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57