Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Plotting a Harmonic FUNction
- *Computational Methods Checkpoint 1
- *Due 7 October, 2011 at 17:00
- *By Marc Langer
- */
- //*Importing necessary functionality
- import java.io.*;
- import java.lang.Math.*;
- //Standard Introduction
- public class HarmonicPLotter {
- public static void main(String [] argv) throws IOException {
- //take filename from the argument
- String fileName = argv[0];
- //create output file
- PrintWriter output = new PrintWriter(new FileWriter(fileName));
- //here's where I think I need to get a for loop to get the iteratively expanding sum
- //Defining the number of points we want to plot
- int kmax = 360;
- //Creating a loop. We will need this to get many values of our function for different input values.
- for (int k = 0; k<kmax; k++) {
- /*For each value of k in the loop we want to map the interger k to a value between (-Pi and Pi Radians. To do this we define a "double" and mupltiply the value k by 2Pi/(kmax = 360) */
- double x = Math.PI*2.0*k/kmax - Math.PI;
- //Calculate value of function of x.
- double f = Function(x);
- //Printing to the output file and closing it.
- output.printf("%10.5f %10.5f\n", x, f);
- output.close();
- }}}
- static double Function(double x){
- //Defining and Evaluating our Harmonic Function
- return Math.sin((n+1)*x)/(n+1);
- }
- }
Add Comment
Please, Sign In to add comment