complex-numbers

Adding and subtract complex numbers using OOP structure

为君一笑 提交于 2019-12-02 09:05:47
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 setReal(double real){ this.real = real; } public double getImag(){ return imag; } public void setImag

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

∥☆過路亽.° 提交于 2019-12-02 07:50:45
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 X=6; then Y will be calculated as follws: Y^2+X^2=1 ==> Y=sqrt(1 - X^2) = sqrt(1-36) = sqrt(-35) = (0,

Algorithm which adapt (solve) the complex equations ( implicit function f(x,y) )

…衆ロ難τιáo~ 提交于 2019-12-02 04:54:01
问题 I'm trying to adapt some equations (implicit f(x,y)) in order to be able list the Y for corresponding X-Value. The equations could be e.g. as follows: y^2 = x^3 + 2x - 3xy (X^2+y^2-1)^3-x^2y^3=0 X^3+y^3=3xy^2-x-1 X^3+y^2=6xy/sqrt(y/x) cos(PI*Y) = cos(PI.X) Below you can see the plotted equations: Hint, I don't know, but maybe this can be helpful, the following applies: Y^2 + X^2 =1 ==> Y= sqrt(1-X^2) The equations are to be adapt (substitution), so that they are expressed by X (not Y). For y

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

穿精又带淫゛_ 提交于 2019-12-02 01:41:43
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: /*** libiir++.cpp ***/ // we need to include "iir.h" first, as it pulls in <complex.h>, which we need // to

Java math expression parser that can take complex numbers as a variable?

旧时模样 提交于 2019-12-02 01:15:46
I am writing a program in Processing that transforms complex numbers. However, I want to have a method of taking an input string and calculating the transformation using a complex variable. For example: 1/(z+1) (z^2)/(z/2) where z is a complex number. Now, I've looked at JEP and some examples , but I cannot work out if it would allow you to actually enter z as a variable (and in any case it is not free). Is there an expression parser for Java (that works in processing, which uses an old version of java and does not have generics) that I could use to do this? If there is not, could someone

Writing and reading complex numbers using numpy.savetxt and numpy.loadtxt

喜你入骨 提交于 2019-12-02 01:00:28
问题 I need to write and read complex numbers. I would like to use numpy.savetxt and numpy.loadtxt to do so. Since the code that I have written is rather big I created a test file to try to write and read complex numbers. So far I have been able to write complex numbers using numpy.savetxt . The code is the following: import numpy d1 = -0.240921619563 - 0.0303165074169j d2 = -0.340921619563 - 0.0403165074169j d3 = -0.440921619563 - 0.0503165074169j d4 = -0.540921619563 - 0.0603165074169j array =

Writing and reading complex numbers using numpy.savetxt and numpy.loadtxt

大城市里の小女人 提交于 2019-12-01 20:46:21
I need to write and read complex numbers. I would like to use numpy.savetxt and numpy.loadtxt to do so. Since the code that I have written is rather big I created a test file to try to write and read complex numbers. So far I have been able to write complex numbers using numpy.savetxt . The code is the following: import numpy d1 = -0.240921619563 - 0.0303165074169j d2 = -0.340921619563 - 0.0403165074169j d3 = -0.440921619563 - 0.0503165074169j d4 = -0.540921619563 - 0.0603165074169j array = numpy.array([d1, d2, d3, d4]) save = open("test.dat", "w") numpy.savetxt(save, array.reshape(1, array

Why is __muldc3 called, when two std::complex are multiplied?

情到浓时终转凉″ 提交于 2019-12-01 20:41:41
问题 I naively assumed, that the complex number multiplication would be inlined by the compiler, for example for this function: #include <complex> void mult(std::complex<double> &a, std::complex<double> &b){ a*=b; } However, when complied by gcc (with -O2 ), the resulting assembler is surprising (at least for me): mult(std::complex<double>&, std::complex<double>&): pushq %rbx movsd 8(%rdi), %xmm3 movsd (%rdi), %xmm2 movq %rdi, %rbx movsd 8(%rsi), %xmm1 movsd (%rsi), %xmm0 call __muldc3 movsd %xmm0

F# - How do I extend a type with get_Zero so I can use an existing type generically?

守給你的承諾、 提交于 2019-12-01 17:36:20
I attempt the following: let c x = System.Numerics.Complex(x, 0.0) let sum = [c 1.0; c 2.0] |> List.sum But I get this error: The type 'System.Numerics.Complex' does not support the operator 'get_Zero' I read the rules on type extensions, from https://msdn.microsoft.com/en-us/library/dd233211.aspx , and try to do the following: module ComplexExtension = let c x = System.Numerics.Complex(x, 0.0) type System.Numerics.Complex with // I also tried a bunch of other ways of writing these // as static or instance members, but nothing worked static member Zero = c 0.0 static member One = c 1.0 open

F# - How do I extend a type with get_Zero so I can use an existing type generically?

不问归期 提交于 2019-12-01 17:05:25
问题 I attempt the following: let c x = System.Numerics.Complex(x, 0.0) let sum = [c 1.0; c 2.0] |> List.sum But I get this error: The type 'System.Numerics.Complex' does not support the operator 'get_Zero' I read the rules on type extensions, from https://msdn.microsoft.com/en-us/library/dd233211.aspx, and try to do the following: module ComplexExtension = let c x = System.Numerics.Complex(x, 0.0) type System.Numerics.Complex with // I also tried a bunch of other ways of writing these // as