complex-numbers

Compiling C code in Visual Studio 2013 with complex.h library

瘦欲@ 提交于 2019-11-26 21:18:59
问题 http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx C99 support added visual studio 2013, but I cant use complex.h in my "C" code. #include <stdio.h> #include <complex.h> int main(void) { double complex dc1 = 3 + 2 * I; double complex dc2 = 4 + 5 * I; double complex result; result = dc1 + dc2; printf(" ??? \n", result); return 0; } I get syntax errors. Edit: Sorry for the missing part. error C2146: syntax error : missing ';' before identifier 'dc1'

Complex numbers usage in python [closed]

坚强是说给别人听的谎言 提交于 2019-11-26 19:37:42
I'm a math newbie. Now I'm getting deeper into Python data types. I can't understand how to use a complex number. Please give me examples of usage of complex numbers in Python. rob mayoff In python, you can put ‘j’ or ‘J’ after a number to make it imaginary, so you can write complex literals easily: >>> 1j 1j >>> 1J 1j >>> 1j * 1j (-1+0j) The ‘j’ suffix comes from electrical engineering, where the variable ‘i’ is usually used for current. ( Reasoning found here. ) The type of a complex number is complex , and you can use the type as a constructor if you prefer: >>> complex(2,3) (2+3j) A

Numpy: Creating a complex array from 2 real ones?

那年仲夏 提交于 2019-11-26 18:00:40
问题 I swear this should be so easy... Why is it not? :( In fact, I want to combine 2 parts of the same array to make a complex array: Data[:,:,:,0] , Data[:,:,:,1] These don't work: x = np.complex(Data[:,:,:,0], Data[:,:,:,1]) x = complex(Data[:,:,:,0], Data[:,:,:,1]) Am I missing something? Does numpy not like performing array functions on complex numbers? Here's the error: TypeError: only length-1 arrays can be converted to Python scalars 回答1: This seems to do what you want: numpy.apply_along

C99 complex support with visual studio

独自空忆成欢 提交于 2019-11-26 17:06:09
问题 I would like to use complex numbers as defined in C99, but I need to support compilers which do not support it (MS compilers come to mind). I don't need many functions, and implementing the needed functions on compilers without support is not too difficult. But I have a hard time implementing the 'type' itself. Ideally, I would like to do something like: #ifndef HAVE_CREAL double creal(complex z) { /* .... */ } #endif #ifndef HAVE_CREALF float creal(float complex z) { /* ... */ } #endif But I

Is there any way to use bivariate colormaps in matplotlib?

被刻印的时光 ゝ 提交于 2019-11-26 16:35:26
问题 In other words, I want to make a heatmap (or surface plot) where the color varies as a function of 2 variables. (Specifically, luminance = magnitude and hue = phase.) Is there any native way to do this? Some examples of similar plots: Several good examples of exactly(?) what I want to do. More examples from astronomy, but with non-perceptual hue 回答1: imshow will take an NxMx3 (rbg) or NxMx4 (grba) array so you can do your color mapping 'by hand'. You might be able to get a bit of traction by

C complex number and printf

﹥>﹥吖頭↗ 提交于 2019-11-26 14:11:28
问题 How to print ( with printf ) complex number? For example, if I have this code: #include <stdio.h> #include <complex.h> int main(void) { double complex dc1 = 3 + 2*I; double complex dc2 = 4 + 5*I; double complex result; result = dc1 + dc2; printf(" ??? \n", result); return 0; } ..what conversion specifiers ( or something else ) should I use instead "???" 回答1: printf("%f + i%f\n", creal(result), cimag(result)); I don't believe there's a specific format specifier for the C99 complex type. 回答2:

Use scipy.integrate.quad to integrate complex numbers

这一生的挚爱 提交于 2019-11-26 12:41:26
问题 I\'m using right now the scipy.integrate.quad to successfully integrate some real integrands. Now a situation appeared that I need to integrate a complex integrand. quad seems not be able to do it, as the other scipy.integrate routines, so I ask: is there any way to integrate a complex integrand using scipy.integrate, without having to separate the integral in the real and the imaginary parts? 回答1: What's wrong with just separating it out into real and imaginary parts? scipy.integrate.quad

How to compute Discrete Fourier Transform?

半腔热情 提交于 2019-11-26 11:24:02
I've been trying to find some places to help me better understand DFT and how to compute it but to no avail. So I need help understanding DFT and it's computation of complex numbers. Basically, I'm just looking for examples on how to compute DFT with an explanation on how it was computed because in the end, I'm looking to create an algorithm to compute it. I assume 1D DFT/IDFT ... All DFT's use this formula: X(k) is transformed sample value (complex domain) x(n) is input data sample value (real or complex domain) N is number of samples/values in your dataset This whole thing is usually

Complex numbers usage in python [closed]

不想你离开。 提交于 2019-11-26 06:20:48
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I\'m a math newbie. Now I\'m getting deeper into Python data types. I can\'t understand how to use a complex number. Please give me examples of usage of complex numbers in Python. 回答1: In python, you can put ‘j’

How to compute Discrete Fourier Transform?

自作多情 提交于 2019-11-26 02:24:19
问题 I\'ve been trying to find some places to help me better understand DFT and how to compute it but to no avail. So I need help understanding DFT and it\'s computation of complex numbers. Basically, I\'m just looking for examples on how to compute DFT with an explanation on how it was computed because in the end, I\'m looking to create an algorithm to compute it. 回答1: I assume 1D DFT/IDFT ... All DFT's use this formula: X(k) is transformed sample value (complex domain) x(n) is input data sample