1) Complex numbers are of the form a + ib, where a is the real part and b represents the imaginary part, multiplied by i
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
1) Complex numbers are of the form a + ib, where a is the real part and b represents the imaginary part, multiplied by i
34.64_21.88 23.49_88.18 20.96_33.67 47.78_53.3127.07_38.7880.39_86.59 90.18_10.52 27.76_77.51 94.05_2.34 7.39_69.4122.62_67.30 31.84_61.08 63.10_84.77 28.05_83.8016.90_88.18 2.45_92.27 13.32_19.29 25.11_87.62 51.52_62.2980.97_30.40 86.83_80.31 93.19_8.74 86.11_71.98
complexmatrix2.txt
35.63_9.19 83.94_4.80 86.73_56.82 62.06_56.9243.15_11.7811.46_53.73 24.35_11.08 5.42_89.67 83.93_41.3165.99_26.8622.19_40.69 41.91_45.02 97.97_42.99 39.83_69.8744.18_43.3052.47_65.17 1.59_60.94 87.78_21.10 57.57_51.6922.03_77.50
complexmatrix3.txt
36.43_70.97 75.77_5.23 35.12_93.9887.79_50.38 30.07_80.30 13.23_93.6248.46_85.65 61.16_36.95 44.31_46.71
package complexmatrix;
public class Complex {
}
package complexmatrix;
public class ComplexMatrix { public static void main(String[] args) {
}}
Can i have the java code
1) Complex numbers are of the form a + ib, where a is the real part and b represents the imaginary part, multiplied by i, V-1. For Java purposes, a and bare double- precision floating point numbers. The magnitude of a complex number is Va² + b² To add two complex numbers, add the real parts and then add the imaginary parts. For example, to add (ao + ibo) to (a1 + ib1), the result would be [(ao+a1) + (bo+b₁)]< H Multiplying two complex numbers follows algebraic laws of multiplication, such that (ao + ibo) * (a1 + ib1₁) = (ao a1 + iaob1+ iboa1 - bob1) = (ao a1 - bobi) + (aob1+ boa1) e Dividing two complex numbers requires separating out the real and complex parts, So: J ao+ibo a₁ + ib₁ (a + ib)(a, -ib₁) (a₁ + ib₁)(a)-ib₂) aa₁ +bob₁ af + b} boa-aob₁ af + b} a) Create a class called Complex which implements complex numbers. It should contain the following methods: Complex () - for which the real and imaginary parts are both zero Complex (double a) - which sets the real part to a and the imaginary part to 0 Complex (double a, double b) - sets the real part to a and the imaginary part to be getReal () - returns the real part of the complex number setReal (double a) - sets the real part of the complex number getImaginary() - returns the imaginary part of the complex number set Imaginary (double b) - sets the imaginary part of the complex number ww toString() which returns a String of the format "a + ib" getMagnitude () - returns the magnitude of the complex number add (Complex c)-returns a Complex number representing the sum of the object and the Complex number c subtract (Complex c) - returns a Complex number representing the difference between the object and the Complex number c.< multiply (Complex c) - returns a Complex number representing the product of the object and the Complex number c divide (Complex c) - returns a Complex number representing the quotient of the object divided by the Complex number c
Complex should also implement the Comparable interface and the results should be based on the magnitude of the two imaginary numbers H b) Now, you are going to implement a class called ComplexMatrix that implements an m by n matrix of Complex numbers you implemented above.< It should have the following methods: H ComplexMatrix (int m, int n) - an m x n matrix of O-value complex numbers ComplexMatrix (Complex [] [] input) - a matrix corresponding to the two dimensional array contained in input You will implement the following operations, which will throw a MatrixDimensionException if the operation is not possible due to dimensional incompatibility public ComplexMatrix add (ComplexMatrix cm) - adds the object to the matrix cm and returns a ComplexMatrix public ComplexMatrix mult (ComplexMatrix cm) - multiplies the object with the matrix cm and returns a ComplexMatrix ( public String tostring() - prints out a representation of the matrix where each element of the matrix follows the tostring format of Complex H Next, you will notice three files, complexmatrixl.txt and complexmatrix2.txt and complexmatrix3.txt. You should be able to read these in to create a complex matrix object. Each member of the matrix has the format a b where a is the real part and b is the imaginary part. You must now implement this static method: له public static ComplexMatrix read (String filename) - this will read in the files like complexmatrix1.txt and complexmatrix2.txt and complexmatrix3.txt and return a ComplexMatrix object. This will require you to have to parse in data. The String split () method will come in handy here, as you can pass arguments to it to specify what you want to "split" on. If the data in the file isn't able to form a proper matrix (say rows have different numbers of columns), throw a IncompatibleMatrixException. I've added the file brokenmatrix.txt so you can test this out. Also, it's a good practice to make sure you remove any extraneous whitespace that you've read in from a file using the String.trim() method. (
Similarly, you should implement a non-static method: public void write (String filename) which takes a filename and writes the ComplexMatrix object out to that file using the format in and complexmatrix2.txt and complexmatrix1.txt complexmatrix3.txt. In fact, whatever you output with write should be able to be read in with read.<