Hey sorry I've been working on it so haven't had a chance to check back. Thanks for the help! So far I've written this:
Code:
import java.io.*;
public class Assignment1try2
{
public static void main(String[] args)
{
//Exports the data to an excel file
PrintWriter outputFile = null;
try
{
outputFile = new PrintWriter(new FileOutputStream("outputVelomobile.xls",false));
}
catch(FileNotFoundException e)
{
System.out.println("File error. Program aborted.");
System.exit(0);
}
//Variable declarations for the Quest Velomobile
double n = 0.92;
double rho = 1.20;
double cR = 0.004;
double m = 32+80;
double g = 9.81;
double cD = 0.24;
double area = 0.46;
double valueOne = rho*cD*area;
double valueTwo = cR*m*g;
double initialRootEstimate = 1;
double function, absDifference;
double[] rootEstimate = new double[8];
int numLoops = 0;
int[] powerRider = {25,50,75,100,150,200,300,400};
//Start loop
for (int index=0;index<powerRider.length;index++)
{
numLoops = 0;
do
{
function = -n*powerRider[index] + 0.5*(valueOne*(Math.pow(initialRootEstimate,3))) + (valueTwo*initialRootEstimate);
rootEstimate[index] = initialRootEstimate - (function/((3/2)*(valueOne*(Math.pow(initialRootEstimate,2))) + (valueTwo)));
absDifference = Math.abs(rootEstimate[index] - initialRootEstimate);
initialRootEstimate = rootEstimate[index];
numLoops++;
}
while (absDifference >=1.0E-12);
//Displays data on screen
System.out.println();
System.out.println("The Power is:" + powerRider[index]);
System.out.println("The Root Estimate is:" + initialRootEstimate);
System.out.println("The number of cycles is:" + numLoops);
System.out.println();
//Outputs results on screen
outputFile.println();
outputFile.println("The Power is:" + powerRider[index]);
outputFile.println("The Root Estimate is:" + initialRootEstimate);
outputFile.println("The number of cycles is:" + numLoops);
outputFile.println();
}
outputFile.close();
}
}
It works but the only problem is that we end up with a lot of iterations. Is there any way we can reduce the amount of iterations?
thanks again