472,809 Members | 4,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 12372
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
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
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
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
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
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
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
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
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
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
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.