Dear all,
I'm looking for a routine which calculates the Gamma Function
for a complex valued variable. I'm using
#include <complex>
to work with complex numbers.
I define a complex number as
complex <doublealpha(3. 0, 1.0)
So here alpha is a complex number with real part of alpha = 3.0
and imaginary part of alpha = 1.0.
By now, I've found "gammln" from Numerical Recipes. But
"gammln" is only working for double, i.e. real valued variables.
Typing
complex <doubletau(3.0, 1.0);
cout<<"Gamma(3, 1) "<<gammln(tau)< <endl;
gives
GammaComplexTes t.cpp: In function `int main()':
GammaComplexTes t.cpp:89: error: cannot convert `std::complex<d ouble>'
to `
double' for argument `1' to `DP NR::gammln(doub le)'
It would be much appreciated if someone could tell me
where to find a routine which also allows to use complex valued
variables for the Gamma Function.
Many thanks!
Tina 7 8604
Tina wrote:
I'm looking for a routine which calculates the Gamma Function
for a complex valued variable. I'm using
#include <complex>
to work with complex numbers.
I define a complex number as
complex <doublealpha(3. 0, 1.0)
So here alpha is a complex number with real part of alpha = 3.0
and imaginary part of alpha = 1.0.
By now, I've found "gammln" from Numerical Recipes. But
"gammln" is only working for double, i.e. real valued variables.
Typing
complex <doubletau(3.0, 1.0);
cout<<"Gamma(3, 1) "<<gammln(tau)< <endl;
gives
GammaComplexTes t.cpp: In function `int main()':
GammaComplexTes t.cpp:89: error: cannot convert `std::complex<d ouble>'
to `
double' for argument `1' to `DP NR::gammln(doub le)'
It would be much appreciated if someone could tell me
where to find a routine which also allows to use complex valued
variables for the Gamma Function.
See the websites in this FAQ or ask in a math newsgroup: http://www.parashift.com/c++-faq-lit....html#faq-37.9
Cheers! --M
Hello Tina,
Dear all,
I'm looking for a routine which calculates the Gamma Function
for a complex valued variable. I'm using
<snip>
It would be much appreciated if someone could tell me
where to find a routine which also allows to use complex valued
variables for the Gamma Function.
I am sure that there are libraries available on the net that provide
what you need.
However, in your particular case, the gamma function isn't too
difficult to implement yourself using Lanczos approximation: http://en.wikipedia.org/wiki/Lanczos_approximation
Translating the Python code to C++ gives the program after the
signature. Without any explicit or implied warranty ;-)
HTH,
Loic.
--
#include <complex>
#include <iostream>
using namespace std;
static const int g=7;
static const double pi =
3.1415926535897 932384626433832 795028841972 ;
static const double p[g+2] = {0.999999999999 80993, 676.52036812188 51,
-1259.1392167224 028, 771.32342877765 313, -176.61502916214 059,
12.507343278686 905, -0.1385710952657 2012, 9.9843695780195 716e-6,
1.5056327351493 116e-7};
complex<doubleg amma( complex<doublez )
{
if ( real(z)<0.5 ) {
return pi / (sin(pi*z)*gamm a(1.0-z));
}
z -= 1.0;
complex<doublex =p[0];
for (int i=1; i<g+2; i++) {
x += p[i]/(z+complex<doub le>(i,0));
}
complex<doublet = z + (g + 0.5);
return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
}
int
main()
{
cout << gamma(complex<d ouble>(5,0)) << endl; // should be 4!
}
Tina <ti*********@ya hoo.cawrote:
>I'm looking for a routine which calculates the Gamma Function for a complex valued variable. I'm using
>#include <complex>
>to work with complex numbers. I define a complex number as complex <doublealpha(3. 0, 1.0)
>So here alpha is a complex number with real part of alpha = 3.0 and imaginary part of alpha = 1.0.
>By now, I've found "gammln" from Numerical Recipes. But "gammln" is only working for double, i.e. real valued variables.
That's because the gamma (and hence, the gammaln) function is only
implemented for real-valued arguments by Matlab. Google on
"mathworks" and "gammaln". If you need the complex gamma function,
you may have to write it yourself, and there may be significant
numerical analysis work to get it to function properly.
I'd ask over in sci.math if anyone knows of an algorithm.
Steve
<lo******@gmx.n etwrote:
>complex<double gamma( complex<doublez ) {
if ( real(z)<0.5 ) {
return pi / (sin(pi*z)*gamm a(1.0-z));
}
z -= 1.0;
complex<doublex =p[0];
for (int i=1; i<g+2; i++) {
x += p[i]/(z+complex<doub le>(i,0));
}
complex<doublet = z + (g + 0.5);
return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
The above line has a complex<doublea rgument to pow().
Will that work?
Thanks
Steve
Hello Steve,
complex<doubleg amma( complex<doublez )
{
if ( real(z)<0.5 ) {
return pi / (sin(pi*z)*gamm a(1.0-z));
}
z -= 1.0;
complex<doublex =p[0];
for (int i=1; i<g+2; i++) {
x += p[i]/(z+complex<doub le>(i,0));
}
complex<doublet = z + (g + 0.5);
return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
The above line has a complex<doublea rgument to pow().
Will that work?
I am not a C++ expert, but I believe that <complexis mandated by the
ISO C++ standard to define pow() for the following cases:
template<class Tcomplex<Tpow(c onst complex<T>&, int);
template<class Tcomplex<Tpow(c onst complex<T>&, const T&);
template<class Tcomplex<Tpow(c onst complex<T>&, const complex<T>&);
template<class Tcomplex<Tpow(c onst T&, const complex<T>&);
HTH,
Loic.
Hello Steve,
complex<doubleg amma( complex<doublez )
{
if ( real(z)<0.5 ) {
return pi / (sin(pi*z)*gamm a(1.0-z));
}
z -= 1.0;
complex<doublex =p[0];
for (int i=1; i<g+2; i++) {
x += p[i]/(z+complex<doub le>(i,0));
}
complex<doublet = z + (g + 0.5);
return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
The above line has a complex<doublea rgument to pow().
Will that work?
I am not a C++ expert, but I believe that <complexis mandated by the
ISO C++ standard to define pow() for the following cases:
template<class Tcomplex<Tpow(c onst complex<T>&, int);
template<class Tcomplex<Tpow(c onst complex<T>&, const T&);
template<class Tcomplex<Tpow(c onst complex<T>&, const complex<T>&);
template<class Tcomplex<Tpow(c onst T&, const complex<T>&);
HTH,
Loic.
<lo******@gmx.n etwrote:
>Hello Steve,
return sqrt(2*pi) * pow(t,z+0.5) * exp(-t) * x;
The above line has a complex<doublea rgument to pow(). Will that work?
>I am not a C++ expert, but I believe that <complexis mandated by the ISO C++ standard to define pow() for the following cases: template<cla ss Tcomplex<Tpow(c onst complex<T>&, int); template<cla ss Tcomplex<Tpow(c onst complex<T>&, const T&); template<cla ss Tcomplex<Tpow(c onst complex<T>&, const complex<T>&); template<cla ss Tcomplex<Tpow(c onst T&, const complex<T>&);
Thanks, this does seem to work if I include both <complexand
<cmath>.
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Scott |
last post by:
MySQL calls 4.1.5 a "Gamma" release.
What does that mean?
|
by: Roberto Dias |
last post by:
I developed a DFT routine using a language named "ATP Model Language".
It is based on FORTRAN and specific to electromagnetic transients
simulations, a study field in electrical engineering. Few months ago,
I cought up on C++ readings and, nowadays, fell very bad to retarn to
"FORTRAN". My Discret Fourier Trasmoration Routine (DFT) is used to
filtering data from electrical system by digital relays. Could you
help me with some tips to...
|
by: Pmb |
last post by:
I've been working on creating a Complex class for my own learning purpose
(learn through doing etc.). I'm once again puzzled about something. I can't
figure out how to overload the assignment operator.
Here's what I'm trying to do. I've defined class Complex as
class Complex {
friend ostream &operator<<( ostream &, Complex & );
public:
Complex( float = 0.0, float = 0.0 );
|
by: Paul Brown |
last post by:
I am confused - I have gone through a two day exercise tuning up an
FFT routine, and at the last stage I find that where the biggest gains
were expected, all my conventional understanding of efficient C seems
to be turned on its head.
Up until this point I have achieved good speed improvements following
an evolutionary approach, starting from the routine entry point I have
modified code, run, validated and timed a test case and follow...
|
by: OcelotIguana |
last post by:
Hello,
Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?
Thanks,
OcelotIguana@yahoo.com
| |
by: Jack Daly |
last post by:
I've inherited some code which uses an undocumented feature of a
third-party vendor's library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer to
this struct to other vendor routines. The struct describes a complex
time-varying object, but it basically boils down to an integer, and
there are access routines to get to the current value of this integer.
My problem is:
1) Our code is...
|
by: Sanjay |
last post by:
Hi All,
Is somewhere a routine useful to convert a string to lines of maxsize,
each prefixed with a '>'. This is a typical requirement for 'keeping
existing text while replying to a post in a forum'.
It can be developed, but if something obvious is already there(I being
new to python might not be aware), than it would be great just to reuse
it!
|
by: Independent |
last post by:
Python programmers may find the application to decoding an encrypted map
image format known as Memory Map to produce a standard PNG image file
interesting.
Someone obviously very well versed in Python and in the intricacies of image
files has written a routine to decode originally the UK Landranger maps, so
that they can be used with other mapping and GPS programs apart from the
restricted Memory Map viewer.
You can get the details in...
|
by: james.duckworthy |
last post by:
Python programmers may find the application to decoding an encrypted
map
image format known as Memory Map to produce a standard PNG image file
interesting.
Someone obviously very well versed in Python and in the intricacies
of image
files has written a routine to decode originally the UK Landranger
maps, so
that they can be used with other mapping and GPS programs apart from
|
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,...
|
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...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |