complex-numbers

Why won't boost's bessel function compile with a complex input?

自作多情 提交于 2019-12-12 21:13:57
问题 According to the boost documentation, the boost special functions bessel function (specifically the modified bessel function) should be able to accept a complex input. However, when I attempt to feed it one, I get a compile error complaining that there is no < operator for operand types float and std::complex<float> . Here is my code: using namespace boost::math; std::complex<float> cpxTerm = std::complex<float>(m_u1 * cos(az), -wbar * cos(sin(lim))); std::complex<float> besselTerm = cyl

Fortran sqrt of complex number -1 gives different results

末鹿安然 提交于 2019-12-12 11:05:34
问题 This code print *, sqrt(cmplx(-1)) print *, sqrt(cmplx(-1,0)) print *, sqrt((-1,0)) print *, sqrt(-(1,0)) gives me this output (0.00000000,1.00000000) (0.00000000,1.00000000) (0.00000000,1.00000000) (0.00000000,-1.00000000) I believe that the correct algebra is sqrt(-1)=i . Why the result of the last line? The compiler version is GCC 7.3.0, running on Linux openSUSE 42.2 (x86_64). EDIT Following @francescalus answer I have tried more cases: print *, sqrt((-1,-0)) print *, sqrt((-1,-0.)) print

inconsistent results using isreal

限于喜欢 提交于 2019-12-12 08:05:57
问题 Take this simple example: a = [1 2i]; x = zeros(1,length(a)); for n=1:length(a) x(n) = isreal(a(n)); end In an attempt to vectorize the code, I tried: y = arrayfun(@isreal,a); But the results are not the same: x = 1 0 y = 0 0 What am I doing wrong? 回答1: This certainly appears to be a bug, but here's a workaround: >> y = arrayfun(@(x) isreal(x(1)),a) ans = 1 0 Why does this work? I'm not totally sure, but it appears that when you perform an indexing operation on the variable before calling

Sorting the complex array elements with imaginary part along with it in MATLAB

不问归期 提交于 2019-12-12 04:47:09
问题 I have a set of data points, which are complex numbers which have, let’s say, 8 rows and 6 columns. If you look at the program, you can see that data sets are arranged very randomly. 1st, 2nd, 3rd columns are okay, but 4th column, is bit anomalous. What I mean to say is that after element at B(5, 4) (i.e. 25.9868674011374) it is coming 2.74257567017122 [B(6, 4)] instead of 26.8410063269595 which has gone to B(6, 6). I want that column arranged in ascending order (every sorting should be done

How to convert Mupad symbol 'I' {sqrt(-1)} to 'i' in matlab

扶醉桌前 提交于 2019-12-11 20:13:02
问题 I am trying to evaluate this integral in matlab matlab is treating 'ans' as a symbol because of 'I'. How to convert this 'I' into 'i' so that ans becomes a complex number. much appreciated! 回答1: The symbolic math toolbox has an overloaded double function that can be used to convert from sym to double representation (if the expression is a symbolic constant or is a constant expression). For example: ans_sym = vpa(1+1*i); ans_double = double(ans_sym); Look here for more information: http://www

eigenvectors complex nonsymmetric matrix in R different from Matlab: how to solve the this? [duplicate]

强颜欢笑 提交于 2019-12-11 17:53:56
问题 This question already has an answer here : R and MATLAB returning different eigenvectors (1 answer) Closed 2 years ago . I want to compute the eigenvalues of a complex matrix in R. Comparing the values obtained in MATLAB, I don't get the same eigenvalues obtained in R computing it from the exact same matrix. In R, I used eigen() . In MATLAB used eig() or eigs() (both functions give out the same eigenvalues but different to the R ones). For real matrices, R and MATLAB are consistent. How to

Complex 1i doesn't work properly

孤街浪徒 提交于 2019-12-11 15:27:52
问题 I try to follow example from that website: http://en.cppreference.com/w/cpp/numeric/complex But I get other results. For example for that code: std::complex<double> z1 = 1i * 1i; // imaginary unit squared std::cout << "i * i = " << z1 << '\n'; It works great, I get in the console: i * i = (-1,0) But other example: std::complex<double> z3 = std::exp(1i * M_PI); // Euler's formula std::cout << "exp(i * pi) = " << z3 << '\n'; I get error: call to 'exp' is ambiguous So I tried that one: double PI

Is it possible to access the real and imaginary parts of a complex number with the [] operator in C++

孤街浪徒 提交于 2019-12-11 12:43:47
问题 I'm using the <complex> library in C++. Is it possible to access the real and complex parts of a complex number using the [] operator? I want to use myComplexNum[0] instead of myComplexNum.real() and myComplexNum[1] instead of myComplexNum.imag() . I tried to do it using MingW 4.5.2, and I receive the error: no match found for 'operator[]' . I really need to use the [] operator for now, because otherwise I would have to change hundreds of lines of code. 回答1: Nope. You could derive from std:

abs(double complex) in Cython

给你一囗甜甜゛ 提交于 2019-12-11 07:27:16
问题 How do I get an absolute value for a double complex variable? def f(): cdef double complex aaa = 1 + 2j cdef double bbb = abs(aaa) The second assignment is highlighted yellow in cython -a html output: aaa is converted to python object prior to applying abs() . How do I call abs() on c/cpp level? PS I understand that cdef extern from "complex.h": double abs(double complex) would solve it, but I see the following instructions in the generated c/cpp file: #if CYTHON_CCOMPLEX #define __Pyx_c_abs

Assigning complex values in gsl

可紊 提交于 2019-12-11 07:26:09
问题 I am trying to use GSL for complex numbers , complex vectors and complex matrices in my project. I am using VS2010 and I added the address of library in Configuration Properties>C/C++>General>Additional Include Directories . But I have a stupid problem. As far as I understood, I can not use = to assign two gsl_complex , gsl_vector_complex or gsl_matrix_complex to each other. For vectors I have to use gsl_vector_complex_set and for matrices gsl_matrix_complex_set . But for gsl_complex, I only