complex-numbers

iPhone — working with complex numbers

二次信任 提交于 2019-12-11 07:24:00
问题 I'm trying to figure out the best way to put complex numbers into my math-oriented iPhone app. I've found the mac osx manual page for complex numbers, which looks like a reasonable start. Three questions: (1) Is this the best starting point? (2) I will need an object-oriented wrapper -- can NSValue do this somehow? Or should I just write my own? (not difficult, but I'd rather use a built-in one if it exists). (3) Is there a built-in way to get a string representation of a complex? 回答1: Seems

How should i get complex numbers from string?

大兔子大兔子 提交于 2019-12-11 07:08:44
问题 I found following pattern from RegexLibrary, and i don't know how use Match to get Re and Im values. I'm new in Regex . Is it a correct way to get data from a pattern? If it's true, I need some sample code! This is what i think it should be: public static complex Parse(string s) { string pattern = @"([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?|[-+]?((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?[i]|[-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?[-+]((\d+\.?\d*|\d*\.?\d+)

Templated class: Check if complex at compile time

让人想犯罪 __ 提交于 2019-12-11 03:34:56
问题 I have a class A templated with a Scalar which can be real- or complex-valued. It has a method realPart which is supposed to return the real part of the number. If Scalar is real-valued, it should just return the original Scalar, and .real() if it's of complex type. When writing #include <complex> #include <iostream> template<class Scalar> class A { public: A (const Scalar z): z_(z) { } Scalar realPart() { return z_.real(); } private: Scalar z_; }; int main() { A<std::complex<double>> z0((1.0

How to store complex numbers in OpenCV matrix?

末鹿安然 提交于 2019-12-11 03:25:59
问题 I have two matrices A and B, where A & B contains some real numbers. Now I want a complex numbered matrix C, such that: C[0] = A[0] + i B[0]. My question is how create such complex matrix C, and how to pass A, B matrices values into matrix C. I came to know that, I can create matrix C as follows: CvMat* C_Matrix = cvCreateMat(5, 5, CV_64FC2); But now how to pass values of A & B to matrix C_Matrix? 回答1: I think you can use merge() function here, See the Documentation It says : Composes a multi

Python3: Calculating complex exponents and logarithms

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 01:37:48
问题 math.exp() doesn't work for complex numbers: >>> math.exp (math.pi*1j) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can't convert complex to float This doesn't hurt me much, as ** works as intended: >>> math.e ** (math.pi*1j) (-1+1.2246467991473532e-16j) Now the problem is with logarithms. math.log doesn't work for negative numbers: >>> math.log(-1) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: math domain error

numpy custom dtype challenge

做~自己de王妃 提交于 2019-12-10 22:50:06
问题 I have an array of custom dtype my_type which I successfully read from a binary file. The custom dtype has a header section after that comes the data. The data part are np.int16 numbers, so the custom dtype looks like this: header, imaginary, real, imaginary, real, ..., imaginary, real Now I am looking for a smart way to use Numpy's view to get an array of np.complex64 of only data without copying/looping etc. considering the following facts: the header part should be ignored somehow correct

Why does clang say _Imaginary_I is not declared?

邮差的信 提交于 2019-12-10 22:24:21
问题 Running clang test.c -o test On this file #include <stdio.h> #include <complex.h> int main() { _Complex double z = 1.0 + _Imaginary_I * 2.0; return 0; } fails to compile because of error: use of undeclared identifier '_Imaginary_I'. According to onlinepubs, _Imaginary_I is defined. What happened? 回答1: Imaginary numbers, and _Imaginary_I , are optional features in the C Standard. Complex numbers are also an optional feature as of C11, but are commonly supported by implementations. I and

Numerically compute derivative of complex-valued function in MATLAB

核能气质少年 提交于 2019-12-10 16:14:50
问题 I would like to compute the derivative of a complex-valued function (Holomorphic function) numerically in MATLAB. I have computed the function in a grid on the complex plane, and I've tried to compute the derivative using the Cauchy–Riemann relations. Given: u = real(f), v = imag(f), x = real(point), y = imag(point) The derivative should be given by: f' = du/dx + i dv/dx = dv/dy - i du/dy where 'd' is the derivative operator. I've tried the following code: stepx = 0.01; stepy = 0.01; Nx = 2

Multiple roots in the complex plane with R

China☆狼群 提交于 2019-12-10 13:40:47
问题 I've been trying to find a function that returns all complex solutions of an equation such as: 16^(1/4) = 2+i0, -2+i0, 0+i2, 0-i2 As it stands, if I enter 16^(1/4) into the console, it only returns 2. I can write a function for this but I was wondering if there is a simple way to do this in R. 回答1: You need polyroot() : polyroot(z = c(-16,0,0,0,1)) # [1] 0+2i -2-0i 0-2i 2+0i Where z is a "vector of polynomial coefficients in increasing order". The vector I passed to z in the example above is

Performing matrix operations with complex numbers in C

穿精又带淫゛_ 提交于 2019-12-10 10:19:40
问题 I'm trying to perform computations involving matrix operations and complex math - sometimes together, in C. I'm very familiar with Matlab and I know these types of computations could be performed simply and efficiently. For example, two matrices of the same size, A and B, each having elements of complex values can be summed easily through the expression A+B. Are there any packages or techniques that can be recommended to employ programming these types of expressions in C or Objective C? I am