M
michalik.ireneusz
This is my program to find zero however it will not print and i cannot
find the mistake i mad. it might have to do with the out.close but i
am not sure can anyone fix it for me
/**
* Given an equation and a high and low , This program will find the
zero using recursion
*
* @author (Dan Michalik)
* @version (10/25/08)
*/
import java.io.*;
import java.lang.Math;
public class Main
{
File outfile;
PrintWriter out;
public void main()
{
// This prints the answer to a specific file
outfile = new File ("H:/results.txt");
try
{
out = new PrintWriter(outfile);
out.println("The zero of the given function is as follows...");
out.println();
Loop();
out.println();
out.println("This program was created by Dan Michalik");
System.out.close();
} catch(FileNotFoundException e) {};
}
double fofx (double x)
//coverts equation into a variable
{
double y = ((x*x*x*x)+6.01*(x*x*x)-51.728*(x*x)-110.55424*(x)
+76.9776);
return y;
system.out.print (fofx)
}
double signum (double x)
//determines if the variable is positive, negative, or zero
{
if (x<0){return 1;}
if (x==0){return 0;}
return -1;
}
double abs (double x)
//gives the absolute value of the equation
{
if (x<0){x = x * -1;}
return x;
}
double zero (double lo, double hi)
// recursion method that finds zero
{
double xmid = (hi + lo) / 2;
if ((abs(fofx(xmid))) <= .000001) {out.println(xmid); return
xmid;}
if((signum (fofx(xmid)) == signum (fofx(hi)))) {hi=xmid;}
if((signum (fofx(xmid)) == signum (fofx(lo)))) {lo=xmid;}
return zero (lo,hi);
}
void Loop()
{// this is the loop that perform the zero function
double x = -100.12347;
while (x <= 100.12347)
{ if (signum(fofx(x)) != signum(fofx(x+.01))) {zero(x+.01,x);}
x = (x+.01);
}
}
}
find the mistake i mad. it might have to do with the out.close but i
am not sure can anyone fix it for me
/**
* Given an equation and a high and low , This program will find the
zero using recursion
*
* @author (Dan Michalik)
* @version (10/25/08)
*/
import java.io.*;
import java.lang.Math;
public class Main
{
File outfile;
PrintWriter out;
public void main()
{
// This prints the answer to a specific file
outfile = new File ("H:/results.txt");
try
{
out = new PrintWriter(outfile);
out.println("The zero of the given function is as follows...");
out.println();
Loop();
out.println();
out.println("This program was created by Dan Michalik");
System.out.close();
} catch(FileNotFoundException e) {};
}
double fofx (double x)
//coverts equation into a variable
{
double y = ((x*x*x*x)+6.01*(x*x*x)-51.728*(x*x)-110.55424*(x)
+76.9776);
return y;
system.out.print (fofx)
}
double signum (double x)
//determines if the variable is positive, negative, or zero
{
if (x<0){return 1;}
if (x==0){return 0;}
return -1;
}
double abs (double x)
//gives the absolute value of the equation
{
if (x<0){x = x * -1;}
return x;
}
double zero (double lo, double hi)
// recursion method that finds zero
{
double xmid = (hi + lo) / 2;
if ((abs(fofx(xmid))) <= .000001) {out.println(xmid); return
xmid;}
if((signum (fofx(xmid)) == signum (fofx(hi)))) {hi=xmid;}
if((signum (fofx(xmid)) == signum (fofx(lo)))) {lo=xmid;}
return zero (lo,hi);
}
void Loop()
{// this is the loop that perform the zero function
double x = -100.12347;
while (x <= 100.12347)
{ if (signum(fofx(x)) != signum(fofx(x+.01))) {zero(x+.01,x);}
x = (x+.01);
}
}
}