I have a for loop testing the max of a function:
function Start
max_i = 0;
max_j = 0;
max_value = 0;
for i =1:3500
for j = 1:3500
new_value = CalcUFamily(i,j);
if new_value > max_value;
max_value = new_value;
max_i = i;
max_j = j;
end
end
end
max_i
max_j
end
function uFamily = CalcUFamily(hh,hw) %h = male, w = wife
(code)
end
The basic is that it is testing a function that I have been trying to optimize (with some help from here) but which I have so far failed to do. I therefore want to test to make a loop that tests all possible values, work hours for a husband and a wife, from 1 h to 3500 h (yearly). I then want to get the highest utility value from CalcUFamily and its corresponding input variables, hh and hw (called i and j in the function above).
My code works well, apart from the fact that it takes too long to run since it runs 12 250 000 times. I therefore want to rase the test interval from 1 to 10 or maybe even 100. Is this possible with the for code, or do I have to rewrite it somehow?
Thanks a lot for your help!