Guest User

Untitled

a guest
Jan 5th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. /*Plotting a Harmonic FUNction
  2. *Computational Methods Checkpoint 1
  3. *Due 7 October, 2011 at 17:00
  4. *By Marc Langer
  5. */
  6.  
  7. //*Importing necessary functionality
  8. import java.io.*;
  9. import java.lang.Math.*;
  10.  
  11. //Standard Introduction
  12. public class HarmonicPLotter {
  13.     public static void main(String [] argv) throws IOException {
  14.  
  15.  
  16.     //take filename from the argument
  17.     String fileName = argv[0];
  18.  
  19.     //create output file
  20.     PrintWriter output = new PrintWriter(new FileWriter(fileName));
  21.  
  22.  
  23.   //here's where I think I need to get a for loop to get the iteratively expanding sum
  24.  
  25.     //Defining the number of points we want to plot
  26.     int kmax = 360;
  27.     //Creating a loop. We will need this to get many values of our function for different input values.
  28.     for (int k = 0; k<kmax; k++) {
  29.  
  30. /*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) */
  31.  
  32.     double x = Math.PI*2.0*k/kmax - Math.PI;
  33.  
  34.   //Calculate value of function of x.
  35.     double f = Function(x);
  36.  
  37.  
  38.     //Printing to the output file and closing it.  
  39.     output.printf("%10.5f %10.5f\n", x, f);
  40.  
  41.  
  42. output.close();
  43.     }}}
  44. static double Function(double x){
  45. //Defining and Evaluating our Harmonic Function
  46.  
  47. return Math.sin((n+1)*x)/(n+1);
  48.  
  49. }
  50.        
  51.  
  52. }
Add Comment
Please, Sign In to add comment