473,507 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C code to calculate gradient of a function

Olw
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?

Thanks,

Olw
Oct 25 '06 #1
14 12617
Olw wrote:
Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Google knows all. I bet "Numerical Recipes in C" might also be a safe
bet for a start, but it is not handy at the moment.
Oct 25 '06 #2
Olw
Clever Monkey wrote:
Olw wrote:
>Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Google knows all. I bet "Numerical Recipes in C" might also be a safe
bet for a start, but it is not handy at the moment.
Well, as far as I can see Numerical Recipes in C asks you to write the
command yourself (dfunc?). Also, googling does not seem to yield any
immediate answers.

This should be such a common task, that I bet some C users out there has
some nice code to share? Anyone ;)

Thanks,

Olw
Oct 25 '06 #3

"Olw" <an****@kommtek.comwrote in message
news:eh**********@orkan.itea.ntnu.no...
Hello,

Does anyone have a nice link to some code for calculating the gradient of
a function in C?

Thanks,

Olw
Try in comp.programming
Oct 25 '06 #4

"Olw" <an***********@kommtek.comwrote in message
news:45******@news.broadpark.no...
Clever Monkey wrote:
>Olw wrote:
>>Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Google knows all. I bet "Numerical Recipes in C" might also be a safe
bet for a start, but it is not handy at the moment.

Well, as far as I can see Numerical Recipes in C asks you to write the
command yourself (dfunc?). Also, googling does not seem to yield any
immediate answers.

This should be such a common task, that I bet some C users out there has
some nice code to share? Anyone ;)

Thanks,

Olw
If you know your function, you should be able to determine its gradient.
For example, if
f(x,y,z) = 2*x + 3*y**2 -sin(z)
then the gradient is the vector
( 2, 6*y, -cos(z) )

If you only have a bunch of points and do not explicitly know
the function, you have to decide how you are going to compute
the gradient. You have to decide how to create the approximation
of the data fit - linear, piecewise linear, least squares, polynomial,
cubic spline, quaternary spline, piecewise continuous multivariate
spline interpolation, ... there are literally an infinite number of
ways you could choose to fit the data. But YOU have to choose.

Check the Linpack, Mathlib, etc., libraries for some possibilities.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Oct 25 '06 #5

Olw wrote:
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Most C functions aren't even differentiable.

--
Bill Pursell

Oct 25 '06 #6
Olw wrote:
>
Does anyone have a nice link to some code for calculating the gradient
of a function in C?
If the longest line in the function is 60 chars, and the function
takes 30 lines, the gradient is height/width, or 30/60, i.e. 1 in
2.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Oct 25 '06 #7

Olw wrote:
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?
news:sci.math.num-analysis is probably the best place for this post.

Maybe:
http://www.google.com/search?hl=en&l...erentiation%22

Oct 25 '06 #8
On Wed, 25 Oct 2006 20:39:24 +0200, in comp.lang.c , Olw
<an***********@kommtek.comwrote:
>This should be such a common task, that I bet some C users out there has
some nice code to share? Anyone ;)
Quite possibly. However this isn't comp.sources.wanted, and the
question isn't a C question, its an algorithm question. You need to
ask in comp.programming or somewhere similar. And do a websearch.

And there quite probably isn't a single generic solution.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 25 '06 #9

Olw wrote:
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?

Thanks,

Olw
This is only an amateur work.

http://www.geocities.com/xhungab/calculus.html

16 Partial differentiation..
c16a.zip : Plot the functions f(x,y)
c16f.zip : Partial derivatives.
c16g.zip : Newton's method for the system of two equations in two
unknowns.
c16h.zip : Implicit differentiation.
c16i.zip : The gradient. The directionnal derivative.
c16j.zip : The gradient. The directionnal derivative. [II]
c16k.zip : Tangent plane, Normal line, level curve.
c16l.zip : Local maximum, minimum, saddle point.
c16m.zip : Local maximum, minimum, saddle point. (II)

Oct 26 '06 #10

Olw wrote:
Clever Monkey wrote:
Olw wrote:
Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Google knows all. I bet "Numerical Recipes in C" might also be a safe
bet for a start, but it is not handy at the moment.

Well, as far as I can see Numerical Recipes in C asks you to write the
command yourself (dfunc?). Also, googling does not seem to yield any
immediate answers.

This should be such a common task, that I bet some C users out there has
some nice code to share? Anyone ;)
I suggest you ask in sci.math.nun-analysis.

I also suggest that you ask about the problem you are trying to solve,
rather than what you think you need to do to solve the problem
(you may or may not be right).

-William Hughes

Hint. Do you think this makes sense? "The reason that Numerical
Recipes does not provide a general gradient function is that the
authors are incompetent and/or lazy."

Oct 26 '06 #11
Olw
Olw wrote:
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?

Thanks,

Olw
Thanks for all the nice inputs.

I will try to find a way based on this.

Olw
Oct 26 '06 #12
Olw
William Hughes wrote:
Olw wrote:
>Clever Monkey wrote:
>>Olw wrote:

Does anyone have a nice link to some code for calculating the gradient
of a function in C?

Google knows all. I bet "Numerical Recipes in C" might also be a safe
bet for a start, but it is not handy at the moment.
Well, as far as I can see Numerical Recipes in C asks you to write the
command yourself (dfunc?). Also, googling does not seem to yield any
immediate answers.

This should be such a common task, that I bet some C users out there has
some nice code to share? Anyone ;)

I suggest you ask in sci.math.nun-analysis.
A scientific analysis of nuns seems quite interesting ;)
>
I also suggest that you ask about the problem you are trying to solve,
rather than what you think you need to do to solve the problem
(you may or may not be right).

-William Hughes

Hint. Do you think this makes sense? "The reason that Numerical
Recipes does not provide a general gradient function is that the
authors are incompetent and/or lazy."
Well, I guess not. But still calculating the gradient should be a quite
common task, and I am also sure that there are plenty of ways doing it
as suggested by Fred L. Kleinschmidt, some of which suit the problem at
hand better than others. Ideally, what I would like to choose from is
some different implementations of this.

Olw
Oct 26 '06 #13

"Olw" <an****@kommtek.comwrote in message
news:eh**********@orkan.itea.ntnu.no...
Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?
Do you mean calculate the gradient at a point, or to differenciate a
function..

Thanks,

Olw

Oct 28 '06 #14
Olw
David Wade wrote:
"Olw" <an****@kommtek.comwrote in message
news:eh**********@orkan.itea.ntnu.no...
>Hello,

Does anyone have a nice link to some code for calculating the gradient
of a function in C?

Do you mean calculate the gradient at a point, or to differenciate a
function..
Sorry about not being precise enough. But it is the gradient at a point
I'm interested in.

Olw
Oct 30 '06 #15

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

Similar topics

4
5164
by: Mark Light | last post by:
Hi, I have a tk.scale bar for which I want the background to change from blue to red as I slide along it. The mechanics of this I can do, but the colour gradient I have is very crude - basically...
13
2052
by: Crirus | last post by:
The main ideea: I havea 513x513 array of values....I draw a sort of map using that values for colors... so I have a realistic lanscape (map). I want to zoom about 60 times that map...and the...
11
4450
by: Maximus | last post by:
Hi all, Has anyone been able to reterive the gradient selection colors used in outlook 2003? Basically, I have a grid showing a list of records and my client wants the selected row to have the...
1
7315
by: Daniel Mark | last post by:
Hello all: I am using PIL to draw a rectangle filled with color blue. Is there anyway I could set the fill pattern so that the drawn rectangle could be filled with gradient blue? Thank...
2
1930
by: moondaddy | last post by:
How do I make a background gradient diagonal instead of just horizontal or vertical? This makes the standard horizontal gradient. progid:dximagetransform.microsoft.gradient(gradienttype=1,...
6
6152
by: moondaddy | last post by:
I want to fill the entire background of a page with a gradient. As a test, I first filled with a solid color like this: <body style="background-color: #ccffff;" > and the entire page was this...
9
8132
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer...
1
7320
by: Allard Warrink | last post by:
I would like to create a transparency gradient over an image using PIL. But I don't have a clue how to do this... Is there anyone out here who could give me some advise?
1
5232
by: cmwb2000 | last post by:
Hi I am trying to calculate the radius of a circle of best fit from 2 or 3 mouse positions. At present I am recording a series of points a mouse passes, I intended to pick the first and last point...
0
7223
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
7110
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
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
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
5623
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,...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.