Due : May 7, 2004. No extensions!
My "hunch" about the geometric series summation working for complex numbers "a" appears to be correct!
Write a Java program that will compute and print the sum of a geometric series
S = a + a^2 + a^3 + ... + a^n
in three different ways: (1) Using a basic for-loop to walk along terms in the series, (2) Using Horner's method of multiplication, and (3) Using the geometric series summation formula. I believe that I have already given you all of the relevant details for method (2) and (3) in class.
The two files that you will need are Complex.java and GeometricSeries.java . The first file is a small library for creating and manipulating complex number objects. You shouldn't need to change this file. The second file is a skeleton solution ... with the key details removed.
You can solve this problem by simply filling in the missing details from GeometricSeries.java.
Here is a fragment of I/O from my solution:
prompt >> java GeometricSeries Welcome to the Geometriic Series Computer ----------------------------------------- Please enter complex number "a" Coefficent a : Real : 1.0 Coefficent a : Imaginary : 2.0 Please enter number of terms in series "a" : 3 The complex no you have entered is :s = 1.0+2.0i No of terms in series is = 3 Summation with basic for-loop ======================================= Summation 1 = -13.0+4.0i Summation using Horner's formula ======================================= Summation 2 = -13.0+4.0i Summation with geometric-series formula ======================================= Summation 3 = -13.0+4.0i
In this case, "a = 1 + 2i" and the series summation has 3 terms.
The corresponding hand calculation is as follows:
S = a + a^2 + a^3 = (1 + 2i) + (1 + 2i)*(1 + 2i) + (1 + 2i)*(1 + 2i)*(1 + 2i) = (1 + 2i) + (1 + 4i - 4) + (1 + 4i - 4 + 2i - 8 - 8i) = -13 + 4i
Your solution to the three parts should be about 30-35 lines of Java, consisting of calls to appropriate methods in the Complex arithmetic library, and for-loop and if-else statements.
Note. Hand in a copy of your program source code and a script of I/O for typical program usage. To create a script, type something like:
prompt >> script output-file
Now all input/output on the screen will be echoed to the file "output-file". To terminate the script, type:
prompt >> exit
Now print "output-file" and hand it in.
Developed in April 2004 by Mark Austin
Copyright © 2004, Department of Civil and Environmental Engineering, University of Maryland