473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

N-dimensional mathematical functions

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
Feb 18 '08 #1
13 2130
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/
Feb 18 '08 #2
On 19 Lut, 00:11, user923005 <dcor...@connx.comwrote:
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?
Feb 19 '08 #3
ja**************@gmail.com 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

Feb 19 '08 #4
ja**************@gmail.com writes:
On 19 Lut, 00:11, user923005 <dcor...@connx.comwrote:
>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.
Feb 19 '08 #5
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?
Feb 19 '08 #6
ja**************@gmail.com 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.

--
Er*********@sun.com
Feb 19 '08 #7
On 19 Lut, 18:48, Eric Sosman <Eric.Sos...@sun.comwrote:
jacek.strzelc...@gmail.com 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.

--
Eric.Sos...@sun.com
Eric, your second solution seems to be quite complicated. It's not my
aim to create my own interpreter. I was thinking about some easy way.
But I think there is no other option despite your first advice -
function pointer.
Keith, I think this is what you've been also saying - that using C
function directly would be the best solution.
Ok, but maybe there is already a parser and interpreter in C to
evaluate multi dimensional mathematical functions? You've mentioned
that I could create it by myself, but isn't there something like this
already?
Feb 19 '08 #8
ja**************@gmail.com writes:
On 19 Lut, 18:48, Eric Sosman <Eric.Sos...@sun.comwrote:
>jacek.strzelc...@gmail.com 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.

--
Eric.Sos...@sun.com
Please don't quote sigs (the -- bit).
Eric, your second solution seems to be quite complicated.
There is a middle way where you don't have to parse the input (if you
don't want to). You use postfix notation and encode that in an array
and interpret it with a little stack machine.

Using $1, $2 for the parameters, your example is:

19.73920 $1 $2 + $1 $2 + $1 $2 + * * 3 * / $1 $2 *

(simpler if you allow a "dup" operation). In C you could have

enum instruction_type {
Number,
Parameter,
Operation
};

enum operation {
Add,
Multiply,
Divide,
/* and do on ... */
};

struct instruction {
enum instruction_type type;
union instruction_data {
double number;
int parameter;
enum operation operation;
} data;
};

It is not too hard to read input and store it in an array of these
instructions and the execution is simple enough. Of course, it may
not be fast enough for some numerical work.

--
Ben.
Feb 19 '08 #9
In article <35**********************************@u69g2000hse. googlegroups.com>,
<ja**************@gmail.comwrote:
>Keith, I think this is what you've been also saying - that using C
function directly would be the best solution.
You would still have to write code to compile it to a temporary
executable and run that executable. This may or may not be easier than
writing a parser yourself, and in any case it will tie your program
down to a particular system, while an expression parser and interpreter
can be done portably.
>Ok, but maybe there is already a parser and interpreter in C to
evaluate multi dimensional mathematical functions? You've mentioned
that I could create it by myself, but isn't there something like this
already?
There isn't (that I know of) a pre-packaged one.
If you don't mind forcing the user to enter the function in something
other than standard mathematical notation, section 4.3 of K&R2
describes a fairly simple RPN calculator; adapting this to your needs
would probably be a worthwhile exercise and would have as its end
result something you can use.
If you need standard mathematical notation and don't mind picking up
new tools, there are code generators like yacc that will do most of the
hard work of generating the parser for you. (You give the code
generator a description of what your input looks like and the code you
want it to run when it parses each sub-expression, and it will generate
C code to parse the input and run your code at appropriate times.)
comp.programming or comp.unix.programmer (or maybe comp.compilers)
would be good places to ask about that.
dave

--
Dave Vandervies dj3vande at eskimo dot com
Well, MS helpfully define a macro ERROR_SUCCESS in winerror.h.
Which, many would say, perfectly describes Windows...
--Mark McIntyre in comp.lang.c
Feb 19 '08 #10
ja**************@gmail.com wrote:
On 19 Lut, 18:48, Eric Sosman <Eric.Sos...@sun.comwrote:
>[...]
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.

Eric, your second solution seems to be quite complicated.
Not very. I've written such a thing in Java and it runs
to only 1036 lines, of which 304 are comments. Java isn't C,
but I imagine a C version would be of similar size.
Ok, but maybe there is already a parser and interpreter in C to
evaluate multi dimensional mathematical functions? You've mentioned
that I could create it by myself, but isn't there something like this
already?
There's no such thing built into the C language or library.
If you search for a term like "expression evaluator" you might
find that somebody else has written something that you could use.
(By the way, I still don't understand why you seem so fixated on
the "multi dimensional" aspect; the same issues arise for user-
entered expressions in one variable, or even in no variables!)

--
Er*********@sun.com
Feb 19 '08 #11
Thanks for the comments. I'll read them through tomorrow, because
today it's already too late for me to understand everything and write
something clever. ;) Then I'll probably have more questions.
Feb 19 '08 #12
Ben, dj3va: Thanks for ideas. I have no question, so I'll try to read
more and implement your solutions.

Eric:
Ok, maybe it's not so complicated, but if there already is something
like that, why create it one more time? ;) And yes, I think you've
called it properly - "expression evaluator', I'll try to look for it.
I'm not fixated on the "multi dimensional" aspect, that's just my
perspective of this problem. ;)

user923005:
Hmmm... right, I'll take that into consideration. Thanks.
Feb 20 '08 #13
ja**************@gmail.com writes:
[...]
Eric:
Ok, maybe it's not so complicated, but if there already is something
like that, why create it one more time? ;) And yes, I think you've
called it properly - "expression evaluator', I'll try to look for it.
I'm not fixated on the "multi dimensional" aspect, that's just my
perspective of this problem. ;)
[...]

I'm still not 100% clear on what you mean by "multi dimensional". Are
you merely referring to functions that take multiple arguments, or is
there more to it?

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 20 '08 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: gelong | last post by:
Hi there, I have a problem in writing a mathematical function using C++ programming. How to write an input that can insert whole equation? Example is the input are x˛ + 3y - 4zł = 0. In maple, it...
14
by: Michael Sgier | last post by:
Hello If someone could explain the code below to me would be great. // return angle between two vectors const float inline Angle(const CVector& normal) const { return acosf(*this % normal); }...
26
by: Joe Blow | last post by:
Some heroes out there generously provide a tarball (usually called "specfun.tar.gz") containing routines that compute special functions like Gamma, Confluent Hypergeometric, Struve, and other...
6
by: Thomas Lumley | last post by:
What does the standard guarantee about the accuracy of eg the trigonometric functions? There is obviously an implementation-dependent upper bound on the accuracy, since the answer is stored in a...
1
by: Jerry chapman | last post by:
Does C# have the standart mathematical functions such as sin,cos etc.? Or does one have to use pinvoke>
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
4
by: Talbot Katz | last post by:
Greetings Pythoners! I hope you'll indulge an ignorant outsider. I work at a financial software firm, and the tool I currently use for my research is R, a software environment for statistical...
2
by: Alan | last post by:
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of...
2
kadghar
by: kadghar | last post by:
Many people asks if there is a way to write a mathematical expression, writen as a string in a text box, so they can do something like: sub something_click() textbox2.text=eval(textbox1.text)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.