473,671 Members | 2,475 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 12666
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.n tnu.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.programmin g
Oct 25 '06 #4

"Olw" <an***********@ kommtek.comwrot e in message
news:45******@n ews.broadpark.n o...
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.n um-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.comwrot e:
>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.wa nted, and the
question isn't a C question, its an algorithm question. You need to
ask in comp.programmin g 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

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

Similar topics

4
5173
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 the amount of R in RGB just increases whilst the G and B are fixed values. Whilst this is not really a python question does anybody have any suggestions about calculating the RGB values for a smooth colour gradient? Mark.
13
2066
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 zoomed area to be drawn on full screen. I want to draw it smoth not a square of 60 pixels x 60 pixels with one color, because I can see blocks and it's not good. There is a way to interpoate the colors between rectangles to show a smoth zoom?
11
4474
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 same selection gradient back color as Outlook 2003 has on its left pane. The selected pane in Outlook 2003 have a gradient orange color for blue color scheme in XP. This gradient color changes according to the color schemes of the windows XP. Can...
1
7412
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 you
2
1936
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, startcolorstr='blue', endcolorstr='whitesmoke',gradientType='2'); Thanks.
6
6157
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 color. next I replaced that with a gradient style like this: <body style="filter:
9
8137
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 display, then only a small portion of the gradient will show if the viewpoint is a smaller PDA or phone display. On the other hand, if viewed full screen on a 1920 pixel wide display, I would run out of gradient on one or both sides of the page....
1
7374
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
5251
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 to calculate the circle but also considering a 3rd point in the centre. Also what about the gradient of the path, could this be used to determin the radius. I am no maths genius, and some of the calculations found online are baffaling, also not...
0
8481
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8823
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6234
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2817
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 we have to send another system
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.