i have comeup with the following now need help as its giving the wrong output
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.Serializable;
public class sim
{
// Initialize variables
Random random = new Random(); // set up random number generator
protected static double temperature = 0.95; // annealing adjustments
protected static double a,y = 0,k = 0,temp = 0; // Variables
protected static double minx = 0; // Constrain of x
protected static double maxx = 40; // Constrain of x
//public boolean anneal(double d);
public static void main( String args[] )
{
double r[]=new double[10];
Random random = new Random(); // How are the inputs will be randomized
// Generate initial x[i] values
//System.out.println("\nx[i] values");
//System.out.println("==================");
for(int i=0;i<10;i++)
{
a = random.nextDouble(); // How are the inputs will be randomized
if((a<maxx) || (a>minx))
{
r[i] = a;
}
// System.out.println(""+r[i]);
// System.out.println("Random number printing");
}
// System.out.println("\nf(x) values");
// System.out.println("==================");
for(int i = 0;i<10;i++)
{
//y = r[i]*r[i]-10*Math.cos(2*3.142*r[i]); // Calculate probabilities
y = Math.sin(0.15*r[i])+ Math.cos(r[i]);
//f(x)=sin(0.15*x)+cos(x)
k = k + y;
// System.out.println(+k);
// System.out.println("Addition formula out come");
}
k = 10*10+k;
// System.out.println("\nf(x) + 10 values returns");
// System.out.println("\n"+k);
//
int l = 1;
while(l != 4) // loop
{
double r1[]=new double[10];
// System.out.println("\nx[i] values");
// System.out.println("==================");
for(int i = 0;i<10;i++)
{
a = Math.random();
if((a<maxx) || (a>minx))
{
// System.out.println("<" + maxx+"Maxx"+" > " + minx + "minxx");
r[i] = a;
}
// System.out.println(""+r[i]);
}
// System.out.println("\nf(x) values");
// System.out.println("==================");
for(int i = 0;i<10;i++)
{
//y = r[i]*r[i]-10*Math.cos(2*3.142*r[i]); // Calculate probabilities
y = Math.sin(0.15*r[i])+ Math.cos(r[i]);
//f(x)=sin(0.15*x)+cos(x)
k = k + y;
// System.out.println(+k);
}
k = 10*10+k;
// System.out.println("\nf(x) + 10 values returns");
// System.out.println("\n"+k);
//Source code:
http://www.heatonresearch.com/articles/9/page4.html /
http://www.heatonresearch.com/code/6...dAnnealing.zip
{
if (temperature < 1.0E-4)
{
if (k > 0.0)
{
temperature = k;
// System.out.println("\nBetter Value = "+k);
// System.out.println(1.0E-4);
}
}
if (Math.random() < Math.exp(k / temperature))
{
// System.out.println(Math.exp(k / temperature)+ " Some equation");
temperature = k;
// System.out.println("\nBetterValue = "+k + "k");
//System.out.println(temp);
System.out.println(temperature + " Temparature");
// ======
//1) Choose a high starting temperature T and a random starting point x. T <- T0, x <- x0
//2) Calculate the function value of the starting point. E <- f (x)
//3) For each iteration k, k = 1 ... kf and while T is sufficiently large, do the following:
//a) Choose a new point x', using a generating function. x' <- g(x)
//b) Calculate the function value of x'. E' <- f (x')
//c) Set x<-x'and E<-E'with probability determined by the acceptance function h(). //d) Reduce the temperature T by //annealing, e.g. T(k+1) <- c*T(k), 0 < c < 1.
//4) Return x and E as the optimal point and the optimal function value.
// ======
}
}
l++;
//System.out.println(l);
}
}
}