Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Runge5 extends Runge2 {
- public static double f(double x, double y) {
- double f = 1000*x;
- return f;
- }
- public static void main(String[] args) {
- try{
- double stepSize = Double.parseDouble(args[0]);
- /* this sets the range of the integral */
- double initial = 0;
- double end = 1;
- /* steps is total steps and finalY is the value of the integral */
- double steps = (end - initial) / stepSize;
- double i = 0;
- double finalY = 0;
- if (stepSize <= 0)
- throw new Exception("Error: Stepsize is negative or 0. \n");
- for (i = 0; i < steps ; i++){
- finalY += rk(initial + i * stepSize,
- 0, stepSize);
- }
- System.out.printf("The Runge Kutta method gives the value \n" );
- System.out.printf("%1.4f as the integral of x^5 * e^x^3 \n",
- finalY);
- System.out.printf("on the interval of %1.4f to %1.4f \n",
- initial, end );
- System.out.printf("using %1.0f steps and a step size of %1.6f \n",
- steps,stepSize);
- if (stepSize > 1.0)
- throw new Exception("Warning: Stepsize is large. Values may be off.\n");
- }
- catch(Exception e){
- System.out.printf(e.getMessage());
- System.out.printf("\nYou need to input a float point value \n");
- System.out.printf("For the value of the step size. To get a \n");
- System.out.printf("reasonable answer, this step size should \n");
- System.out.printf("be fairly small, non-negative and entered \n");
- System.out.printf("FUCKas a command line argument, thank you. \n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement