Question: Programming with Arrays Write a short program to calculate the second derivative of an array of doubles. Starting with Lab.java (shown below), finish the program

Programming with Arrays

Write a short program to calculate the second derivative of an array of doubles. Starting with Lab.java (shown below), finish the program to compute and print the discrete second derivative of the array read in by adding code everywhere it says // [Add code here]. The first line of input will tell how many values are in the array. Next, the data points will be give, one per line. import java.util.*; public class Lab { public static void main(String args[]) { Scanner scan = new Scanner(System.in);

// Read in the number of data points int numDataPoints = scan.nextInt();

// Create an array to hold the data points, and another to // hold the second derivative double data[] = new double[numDataPoints]; double secondDerivative[] = // [Add code here]

// Read in all of the data points using a for loop // [Add code here]

// Print out the data using printArray printArray(data); System.out.println();

// Create the second derivatives and store them in the // secondDerivative array. // (Since the first and last elements of the array do // not have neighbors, set their second derivatives to 0.) // [add code here]

// Print the second derivative array by calling printArray // [add code here] }

public static void printArray(double[] arr) { // Print the values of arr on a single line with spaces between them. // [Add code here] } }

Entering Data and Running the Program Now we need some data. Type in, or copy the following input file, and call it labinput.txt: 9 1.1 2.2 3.3 2.2 1.1 7.0 8.0 9.1 10.0 Run your second derivative program with the input file you have just entered: java Lab < labinput.txt Run the program again, redirecting (use >) the output to labout.txt.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!