[CppAD] Using Complex Types

Brad Bell bradbell at seanet.com
Fri Oct 5 10:53:24 EDT 2007


The requirements to use the CppAD type AD<Base> where Base is not float, 
double are given in
    http://www.coin-or.org/CppAD/Doc/base_require.xml

These requirements are part of the distribution for the cases where Base 
is std::complex<float> or std::complex<double>. This is intended as an 
example of how to use CppAD with an arbitrary Base type; see
    http://www.coin-or.org/CppAD/Doc/base_complex.hpp.xml

The functions real(x), imag(x), conj(x) and abs(x) are examples of 
functions that are not complex differentiable. If you use these 
functions in the algorithm that you are differentiating, I suggest that 
you use the type
    std::complex< CppAD::AD<double> >
for your complex calculations. If  x has this type,  x.real() will have 
the type AD<double> (so will x.imag()). Thus you will be able to 
differentiate results that depend on these values.

I have created an example that uses std::complex< CppAD::AD<double> >; see
    
https://projects.coin-or.org/CppAD/browser/trunk/example/not_complex_ad.cpp

This example will be part of the distribution starting with version 
cppad-20071006 (tomorrow). At that point you will be able to view this 
example as part of the documentation at
    http://www.coin-or.org/CppAD/Doc/not_complex_ad.cpp.xml
or
    http://www.coin-or.org/CppAD/Doc/not_complex_ad.cpp.htm

Tore.Kleppe at math.uib.no wrote:
> Dear Dr. Bell
>
> I did recently download the CppAD library since I learned that this library
> facilitates AD computations with complex types. In this context I have a quick
> question: Is it possible to use the real() and imag() functions within an active
> section? If so - what is the syntax to access these?
>
> The function I attempt to differentiate has real input and output, but some of
> the computations within involves complex variables.
>
> Kind regards
>
> Tore Kleppe
> PhD student
> Dep. Mathematical Sciences
> University of Bergen 
>
>
>
>   



More information about the CppAD mailing list