complex-numbers

scipy odeint with complex initial values

帅比萌擦擦* 提交于 2020-01-13 18:55:13
问题 I need to solve a complex-domain-defined ODE system, with complex initial values. scipy.integrate.odeint does not work on complex systems. I rod about cutting my system in real and imaginary part and solve separately, but my ODE system's rhs involves products between dependent variables themselves and their complex conjugates. Haw do I do that? Here is my code, I tried breaking RHS in Re and Im parts, but I don't think the solution is the same as if I wouldn't break it because of the internal

range builder `r_` - slice with complex (but not imaginary) step; magnitude is used

爷,独闯天下 提交于 2020-01-09 11:52:15
问题 Playing with the NumPy concatenation and range building object r_ I stumbled over the following behavior: apparently, a complex step no matter whether real, imaginary or proper complex has its absolute value taken as the number of steps in a linspace like way. >>> import numpy as np >>> >>> np.r_[0:12:4] # start : stop : step array([0, 4, 8]) # that's expected >>> np.r_[0:12:4j] # start : stop : imaginary step array([ 0., 4., 8., 12.]) # that's in the docs >>> np.r_[0:12:4+0j] # real step of

cuda, pycuda — how to write complex numbers — errors:class “cuComplex” has no member “i”

柔情痞子 提交于 2020-01-06 14:52:11
问题 I have difficulties to use complex numbers in cuda,pycuda. I have this in C: #include <complex> typedef std::complex<double> cmplx; .... cmplx j(0.,1.); Also,in the same code: #include <boost/python.hpp> #include <boost/array.hpp> ... typedef std::vector< boost::array<std::complex<double>,3 > > ComplexFieldType; typedef std::vector< boost::array<double,3> > RealFieldType; ... __global__ void compute(RealFieldType const & Rs,ComplexFieldType const & M,..) ... How can i convert this to use it

Bogus parsing/eval of complex literals

 ̄綄美尐妖づ 提交于 2020-01-06 03:06:08
问题 When evaluating complex numbers, python likes to fiddle the signs. >>> -0j (-0-0j) >>> (-0-0j) 0j Why? nb: I noticed it when reading this question. 回答1: The issue here is that Python doesn't parse complex numbers such as (-0-0j) as literals, they are actually parsed as an expression: >>> import ast >>> ast.dump(ast.parse('(-0-0j)')) 'Module(body=[Expr(value=BinOp(left=UnaryOp(op=USub(), operand=Num(n=0)), op=Sub(), right=Num(n=0j)))])' So, this is not a complex literal but a reflected

How to find out if the Sympy variable is complex?

怎甘沉沦 提交于 2019-12-31 05:03:10
问题 I am writing a code which involves solving this equation X = solve(Theta_Mod_Eqn*Ramp_Equation/(x+PT) - C, x) I am using sympy library, now the equation has 7 roots few are complex and few are real. I am unable to segregate them because isinstance(i,complex) is always returning true for i in X: if not isinstance(i,complex): if (i>-0.01 and i<maxSheaveDisp): A = i; for one case i = -0.000581431210287302 - 0.2540334478167*I In:i == complex Out[39]: False How to find out if the variable is

numpy read .csv with complex number

删除回忆录丶 提交于 2019-12-30 11:18:26
问题 stackoverflow, I have a matrix containing complex numbers (ex. -2.2982235934153075E-11+2.1179547211742553E-9i) that I need to import to a numpy array. I've been using genfromtext(file) to parse all my other, real values, but I'm getting a nan for all complex values. Any ideas? self.raw = (genfromtxt(self.loc, delimiter=',', skip_header=9, dtype=float)) [m,n] = shape(self.raw) data = zeros((m, n-3)) data[:, :] = self.raw[:, 3::] returns: data = array([nan, nan, nan, ...]) 回答1: You can do:

How to set the imaginary part of a complex number to zero?

a 夏天 提交于 2019-12-30 10:15:09
问题 I need to check if the imaginary part is very small and set it to zero if it is in order to eliminate some floating point errors that result in very small non-zero imaginary parts when it should be zero. My code is as follows: kz2 = SQRT((n2*(2.0*PI*eta))**2 - kxarray(p)**2) kz1 = SQRT((n1*(2.0*PI*eta))**2 - kxarray(p)**2) if (aimag(kz2) < 0.0005) then kz2 = (REAL(kz2),0.0) end if if (aimag(kz1) < 0.0005) then kz1 = (REAL(kz1), 0.0) end if Unfortunately the compiler just returns: gaussian1

Sort complex vectors in specific order

放肆的年华 提交于 2019-12-25 09:34:00
问题 I have vector with eigenvalues: e = -0.4094 + 3.9387i -0.4094 - 3.9387i -0.0156 + 0.5645i -0.0156 - 0.5645i And I would like to sort this vector like that: e_sort = -0.0156 + 0.5645i -0.4094 + 3.9387i -0.0156 - 0.5645i -0.4094 - 3.9387i The rule is: First must be: -a+b*i and then: -a-b*i We can say, that: 0 < b_1 < b_2 < ... < b_n Thanks, 回答1: e1 = e(imag(e) >= 0); e2 = e(imag(e) < 0); newe = cat(1,sort(e1),sort(e2)) newe = -0.0156 + 0.5645i -0.4094 + 3.9387i -0.0156 - 0.5645i -0.4094 - 3

Complex number program compile-time error at calculation methods

你说的曾经没有我的故事 提交于 2019-12-25 09:18:23
问题 class Complex { public: Complex(float = 0.0, float = 0.0); //default constructor that uses default arg. in case no init. are in main void getComplex(); //get real and imaginary numbers from keyboard void sum(Complex, Complex); //method to add two complex numbers together void diff(Complex, Complex); //method to find the difference of two complex numbers void prod(Complex, Complex); //method to find the product of two complex numbers void square(Complex, Complex); //method to change each

only display real value from complex array javascript

走远了吗. 提交于 2019-12-24 14:15:06
问题 This question is similar to one of my previous questions (removing objects in an object in an array javascript). However instead of having only numbers, there are also complex numbers with "NaN" as the real values. I thought this could be happening since I'm using big numbers and Mathjs, but all of my other values are already floated to ~15 decimal places. The returned array froma console.log(realPowers) looks like this in the console log: 0:0 1:91.51069578156118 2:183.02210760273937 3:277