//========================================================================= #define PROGRAMMER "SOLUTIONS, Nofrills" #define PROG_CODE "soln" #define COURSE "ECE-1021" #define YEAR (2004) #define TERM "Spring" #define SECTION (0) #define ASSIGNMENT "HW #8A" #define REVISION (0) #define TITLE "Complex Math" #define SUBTITLE "Last Modified on 23 APR 04" #define EMAIL "ece1021@eas.uccs.edu" #define FILENAME "08a0soln.c" //========================================================================= //========================================================================= // PROBLEM //========================================================================= // // Programming Problem #10.3 // // Implement primitive functions and utility functions before implementing // the functions called for in the problem. // //========================================================================= // PSEUDOCODE //========================================================================= // // This is a set of very specific functions and so no detailed pseudocode // is really appropriate. But a description of each function is warranted. // // Structure: // // struct complex // { // double real, imaginary; // }; // typedef struct complex COMPLEX; // // Primitive Functions: // // double GetCOMPLEXreal(COMPLEX a); // double GetCOMPLEXimag(COMPLEX a); // double SetCOMPLEXreal(COMPLEX *a, double real); //returns real // double SetCOMPLEXimag(COMPLEX *a, double imag); //returns imag // // Utility Functions: // // The following can use the Primitives directly: // // Re(a): returns the real part of the complex number a // Im(a): returns the imaginary part of the complex number a // cartesian(real, imaginary): returns a complex number // // The following need to perform polar to rectangular conversions: // // Mag(a): returns the magnitude of the complex number a // |c| = sqrt( (Re(c))^2 + (Im(c))^2 ) // Arg(a): returns the arg (the angle in radians) of the complex number a // arg = atans(Im(c), Re(c)) // polar(magnitude, arg): returns a complex number // Re(c) = magnitude*cos(arg), Im(c) = magnitude*sin(arg) // // Functions: // add_c(a,b) return a + b // Re(c) = Re(a) + Re(b), Im(c) = Im(a) + Im(b) // // sub_c(a,b) return a - b // Re(c) = Re(a) - Re(b), Im(c) = Im(a) - Im(b) // // mul_c(a,b) return a * b // Re(c) = Re(a)Re(b) - Im(a)Im(b) // Im(c) = Re(a)Im(b) + Im(a)Re(b) // Or, using the polar functions: // c = Polar( Mag(a)*Mag(b), Arg(a)+Arg(b) ) // // div_c(a,b) return a / b // c = Polar( Mag(a)/Mag(b), Arg(a)-Arg(b) ) // // read_c(ptr2c) read a complex number from the keyboard and store in c // Have user type in using the form 7+5i (no spaces) // // print_c(a) print out the complex number a // Output in the form " Re(a)+Im(a)i " // // conj_c(a) returns complex conjugate // c = cartesian( Re(a), -Im(a) ) // // abs_c(a) returns magnitude of a (result is double) // m = Mag(a) // // exp_c(a) returns exp(a) (result is complex) // c = cartesian(exp(Re(a))cos(Im(a)), exp(Re(a))sin(Im(a))) }