///////////////////////////////////////////////////////
public class ComplexNumber {
private double x;// store x
private double y;// store y
private double r;// store r
private double angle;// store angle
// default constructor
public ComplexNumber(){
this.setX(0);
this.setY(0);
this.setR(0);
this.setAngle(0);
}
// constructor with arguments
// _b false mean taking vector
// _b true mean taking poler
public ComplexNumber(double _x,double _y,boolean
_b){
if(_b==false){
this.setX(_x);
this.setY(_y);
// create poler
form
this.setR(Math.sqrt(_x*_x+_y*_y));
this.setAngle(Math.atan2(_y,_x));
}
else{
// create vector
form
this.setX(_x*Math.cos(_y));
this.setY(_x*Math.sin(_y));
this.setR(_x);
// reset
angle
this.setAngle(Math.atan2(this.getY(),this.getX()));
}
}
// return vector form
public String
vectorForm(){return("["+this.x+","+this.y+"]");}
// return poler form
public String
polerForm(){return("("+this.r+","+this.angle+")");}
// getter and setter methods
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getR() {
return r;
}
public void setR(double r) {
this.r = r;
}
public double getAngle() {
return angle;
}
public void setAngle(double angle) {
this.angle = angle;
}
}
////////////////////////
public class Driver {
public static void main(String [] args){
ComplexNumber comNum1=new
ComplexNumber(3,4,false);
ComplexNumber comNum2=new
ComplexNumber(10,2.7456,true);
double
angleComNum1=comNum1.getAngle();
double
rComNum1=comNum1.getR();
///// test case 1
if(Math.abs(comNum1.getX()-rComNum1*Math.cos(angleComNum1))<0.00001){
System.out.println("TestCase 1 pass");
}
else{
System.out.println("TestCase 1 fail");
}
///// test case 2
if(Math.abs(comNum1.getY()-rComNum1*Math.sin(angleComNum1))<0.00001){
System.out.println("TestCase 2 pass");
}
else{
System.out.println("TestCase 2 fail");
}
double
xComNum2=comNum2.getX();
double
yComNum2=comNum2.getY();
///// test case 3
if(Math.abs(comNum2.getAngle()-Math.atan2(yComNum2,xComNum2))<0.00001){
System.out.println("TestCase 3 pass");
}
else{
System.out.println("TestCase 3
fail"+Math.atan2(yComNum2,xComNum2));
}
///// test case 4
if(Math.abs(comNum2.getR()-Math.sqrt(Math.pow(xComNum2,2)+Math.pow(yComNum2,2)))<0.00001){
System.out.println("TestCase 4 pass");
}
else{
System.out.println("TestCase 4 fail");
}
System.out.println("");
System.out.println("");
System.out.println("Vector form of
comNum1 : "+comNum1.vectorForm());
System.out.println("Poler form of
comNum1 : "+comNum1.polerForm());
System.out.println("Vector form of
comNum1 : "+comNum2.vectorForm());
System.out.println("Poler form of
comNum1 : "+comNum2.polerForm());
}
}
///////////////////////////
Factory of Complex Numbers A complex number can be expressed in the form of either a...
complex numbers son a) Express Z as a complex number in rectangular form. Z = (5 + 12j).(12 + 5j). e 10 b) Express Z as a complex number in polar form. 2+2+2245° 2=2-2j c) Solve for R and L, where R and L are both real numbers: 200296 + 100Li 102360R
In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, p and q, with the denominator q not equal to zero. Since q may be equal to 1, every integer is a rational number. Define a class that can represent for a rational number. Use the class in a C++ program that can perform all of the following operations with any two valid rational numbers entered at the keyboard...
Al. Practice with complex numbers: Every complex number z can be written in the form z r + iy where r and y are real; we call r the real part of z, written Re z, and likewise y is the imaginary part of z, y - Im z We further define the compler conjugate of z aszT-iy a) Prove the following relations that hold for any complex numbers z, 21 and 22: 2i Re (2122)(Re z) (Re z2) -...
C++ OPTION A (Basic): Complex Numbers A complex number, c, is an ordered pair of real numbers (doubles). For example, for any two real numbers, s and t, we can form the complex number: This is only part of what makes a complex number complex. Another important aspect is the definition of special rules for adding, multiplying, dividing, etc. these ordered pairs. Complex numbers are more than simply x-y coordinates because of these operations. Examples of complex numbers in this...
Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i where i is √-1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values of (1,1) i.e. 1 for the real part and 1 for the imaginary part. Provide public member functions that perform the following...
JAVA PROGRAMMING A complex number is a number in the form a + bi, where a and b are real numbers and i is V-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + di a + bi - (c +...
Plot the complex number on the complex plane and write it in polar form and in exponential form. 3-41 Plot the complex number on the complex plane. Write the complex number 3 - 4 i in polar form. Select the correct choice below and fill in the answer box(es) within your choice. (Simplify your answer. Type an exact answer for r, using radicals as needed. Type any angle measures in radians, rounding to three decimal places as needed. Use angle...
A complex number is a number of the form a + bi, where a and b are real numbers √ and i is −1. The numbers a and b are known as the real and the imaginary parts, respectively, of the complex number. The operations addition, subtraction, multiplication, and division for complex num- bers are defined as follows: (a+bi)+(c+di) = (a+c)+(b+d)i (a+bi)−(c+di) = (a−c)+(b−d)i (a + bi) ∗ (c + di) = (ac − bd) + (bc + ad)i (a...
A complex number is a number in the form of a + bi, where a and b are real numbers and i is the square root of negative 1. Design and create a class called Complex for representing complex numbers. This class should have two attributes, a and b, which represent the parts of the complex number. This class should overload the +,-,*,/,++ and -- operators (both prefix and suffix) to perform basic complex number calculations according to the following...
[8] Plot the following complex number in the complex plane, write it in "long-hand" polar form with the argument in degrees, and write it in rectangular form. 137 5 cis 18 long-hand: rectangular: 19] Simplify (2)3 + 2i)". Write and circle your answer in both r cis 0 and x + yi form. [10] Solve for the variable over C. Circle answers in r cis form. x = 641 [11] Solve for the variable over C. Circle answers in rcise...