|
CS 2073, Fall 2005 Program 11 Complex Numbers Due (on time): 2005-11-30 23:59:59 Due (late): 2005-12-02 23:59:59 |
|
Program 11 must be emailed to:
nrwagner@cs.utsa.edu following directions for: running and submitting a C program, with deadlines:
|
Note: If you are working in the CS lab, Science Building 1.02.04, the old Visual C++ 6.0 is now gone. Instead you must use Visual C++ 2005 Express Edition. Directions for using this are at: running.
C does not support complex numbers in any way. Thus it is illegal to write anything such as sqrt(-1) in C. Some languages, such as Fortran, have built-in facilities for complex numbers. In other languages such as C++, it is reasonable to write library code that makes it look as if complex numbers are a built-in type. C is in the middle between these two extremes. So we are going to have to do everything "by hand", just as with fractions.
As with fractions, you must use the followings struct to represent a complex number ("must" because I want you to practice with structs):
struct complex { /* a complex number: real + imag i */
double real; /* real part of the complex number */
double imag; /* imaginary part of the complex number */
};For operations with these complex numbers, we have to fall back to the definitions of each operation. At least we don't have to use the gcd or reduce functions, as we did with fractions. (Things are a bit simpler with complex numbers.)
You need to translate each of these into C functions that make use of the struct complex, in a way similar to the C functions that implement fractions.
| First 4 terms of the series for exp(0 + pi i) |
|---|
Calulating exp(0 + 3.141592653589792i)
# 0, term: ( 1.00000000000000, 0.00000000000000), abs: 1.00000000000000
sum: ( 1.00000000000000, 0.00000000000000), abs: 1.00000000000000
# 1, term: ( 0.00000000000000, 3.14159265358979), abs: 3.14159265358979
sum: ( 1.00000000000000, 3.14159265358979), abs: 3.29690830947561
# 2, term: (-4.93480220054467, 0.00000000000000), abs: 4.93480220054467
sum: (-3.93480220054467, 3.14159265358979), abs: 5.03510404644239
# 3, term: (-0.00000000000000,-5.16771278004996), abs: 5.16771278004996
sum: (-3.93480220054467,-2.02612012646017), abs: 4.42581417642655
|
|
Contents of email submission
for Program 11: Last Name, First Name; Course Number; Program Number.
|