I need help in writing a simulated annealing algorithm that is able to maximize f(x)=sin(0.15*x)+cos(x) defined on the interval 0<= x <= 40 using the cooling schedule. Please help me as i'm supposed to generate random numbers between 0 and 40 and substitute in f(x)=sin(0.15*x)+cos(x)......


You could attack this solution in this way: consider the x value that produces the maximum value for the function as a value that is to be "searched". And start off with an algorithm one like the binary search.
To put this into perspective, suppose 0-40 is your range set for values of x. You calculate the value of f(x) for the lowest possible value of x in the range set - 0 and the highest possible value for x in the range set - 40. Whichever x produces a larger f(x) value, you would divide the current range set into two halves and define the new range set as the half containing the value of x that produced a larger value of f(x). So if f(40) > f(0), your next range set would be 20<=x<=40 and so on. In this way you "chase" the value of x that will produce the max value of f(x).