complex-numbers

How to round up a complex number?

五迷三道 提交于 2019-12-22 07:10:47
问题 How can I round up a complex number (e.g. 1.9999999999999998-2j ) as 2-2j ? When I tried using print(round(x,2)) it showed Traceback (most recent call last): File "C:\Python34\FFT.py", line 22, in <module> print(round(x,2)) TypeError: type complex doesn't define __round__ method 回答1: Round real part and imaginary part separately and combine them: >>> num = 1.9999999999999998-2j >>> round(num.real, 2) + round(num.imag, 2) * 1j (2-2j) 回答2: If all you want to do is represent the value rounded as

How to express tetration function, for complex numbers

吃可爱长大的小学妹 提交于 2019-12-21 19:56:33
问题 There do exists so-called hyperoperation sequence. It works like you construct multiplication a*b=a+a+a+a...+a with many additions of a repeated b times. Then there goes exponentiation a^b = a*a*a*a*...*a with many multiplicaitions of a repeated b times. Then, there goes tetration, expressed as a tower of exponentiations, same like a^^b == a^a^a^...^a , repeated b times. I am interested how to write this function, for floating point and complex numbers? I've alredy wrote multiplication and

Why is complex conjugate transpose the default in Matlab

柔情痞子 提交于 2019-12-21 13:08:13
问题 if A matrix has complex element and I want to transpose A to A' using the command >>A' Why it is design that a+bi be transformed into a-bi ? What it use for? 回答1: From here: for complex matrices, it is almost always the case that the combined operation of taking the transpose and complex conjugate arises in physical or computation contexts and virtually never the transpose in isolation (Strang 1988, pp. 220-221). In matlab if you want to transpose without conjugating use .' . 回答2: Actually I

Why is complex conjugate transpose the default in Matlab

不想你离开。 提交于 2019-12-21 13:07:26
问题 if A matrix has complex element and I want to transpose A to A' using the command >>A' Why it is design that a+bi be transformed into a-bi ? What it use for? 回答1: From here: for complex matrices, it is almost always the case that the combined operation of taking the transpose and complex conjugate arises in physical or computation contexts and virtually never the transpose in isolation (Strang 1988, pp. 220-221). In matlab if you want to transpose without conjugating use .' . 回答2: Actually I

Division by complex<double> in clang++ versus g++

我的未来我决定 提交于 2019-12-21 07:19:15
问题 When I compile the following code with g++ (4.8.1 or 4.9.0) or clang++ (3.4) I get different outputs. #include <iostream> #include <complex> int main() { std::complex<double> c = {1.e-162,0}; std::cout << 1.0/c << std::endl; return 0; } g++: (1e+162,0) clang++: (inf,-nan) Is this a bug in clang? Update: Thank you for your answers! I reported the bug: http://llvm.org/bugs/show_bug.cgi?id=19820 回答1: The standard says in [complex.numbers] (26.4/3): If the result of a function is not

How to find Y for corresponding X values (Implicit function, Complex number)

*爱你&永不变心* 提交于 2019-12-20 07:43:53
问题 Given is the equation: Y^2 = X^3 + 2*X - 3*X*Y Assuming the plotted sketch is correct. Y^2 = X^3 + 2*X - 3*X*Y Hint: Y^2 + X^2 =1 ==> Y= sqrt( 1 - X^2 ) The X values are known. How can I find the corresponding Y values for X values? E.g. for known X-Values, I expect something like below listed Y-Values (see the plotted sketch): X= 1 ; Y=0.79 X=2 ; Y=1.58 X=3 ; Y=2.79 X=4 ; Y=4.39 X=5 ; Y=6.33 X=6 ; Y=8.57 X=7 ; Y=11.12 X=8 ; Y=13.92 X=9 ; Y=16.98 X=10 ; Y= 20.29 E.g. I will try to find Y for

Adding and subtract complex numbers using OOP structure

余生长醉 提交于 2019-12-20 05:49:30
问题 I have here a code that should print the sum and difference of two complex numbers. The instructions given are: make the methods add , subtract , and print to be void and test using the constructor's object. public class Complex { /** * @param args */ public double real; public double imag; public String output = ""; public Complex(double real, double imag){ this.real += real; this.imag += imag; } public Complex(){ real = 0; imag = 0; } public double getReal(){ return real; } public void

sorting a complex vector by imaginary part in R

守給你的承諾、 提交于 2019-12-20 04:42:36
问题 roots <- polyroot(c(5, 4, 3, 2, 1)) I want to sort the roots by ascending order of the imaginary part. By default the sort function sorts it by the increasing order of the real part. I've read the document and I still do not know how to adjust the arguments or write the command. Can anybody help? 回答1: Use Im function to extract the imaginary part and sort it. roots <- polyroot(c(5, 4, 3, 2, 1)) #[1] 0.287815+1.416093i -1.287815+0.857897i -1.287815-0.857897i #[4] 0.287815-1.416093i roots[order

Gfortran complex actual to real dummy argument

左心房为你撑大大i 提交于 2019-12-20 04:27:10
问题 I am trying to use fftpack with gfortran, but I am getting errors that i think relate to that some routines are passed complex arrays when the dummy argument is declared as real. I read a comment on an intel fortran page that one could disable " check routine interface ". Does anyone know if there is a similar option for gfortran? I would like to not have to edit the fftpack... ( i guess this is because complex in memory is represented by two reals and the array arguments are passed as

c++ and <complex.h> with <complex> in separate files

旧街凉风 提交于 2019-12-20 02:56:38
问题 Notes: I am compiling on OSX using Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Specifically, I am trying to compile a monolithic source from LibIIR, a filter library maintained here by Laurence Withers. I've already looked at this answer here about using both <complex> and <complex.h> in the same file . Setup: I have a file iir.h like so: #include <complex.h> #ifdef __cplusplus extern "C" { #endif ... I have C++ source and header files libiir++.cpp and iir++.h like so: /***