/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-011 * Lesson: Week 8, Day 1 */ public class Compex051_7_2 { // The complex number is // real + imaginary * i // where i is sqrt(-1) private double real; private double imaginary; public Compex051_7_2(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } // // Treat complex number as a vector // and return the magnitude. // // That is, we want to find the length // of the vector from the origin // to the complex number // when plotted on a graph. public double magnitude() { // sqrt(x^2 + y^2) // sqrt(real^2 + imaginary^2) return Math.sqrt(real*real+imaginary*imaginary); } }