My problem is easier to understand with the code that someone help me to accomplished using fminsearch.
h = randi(24,8760,1);
nd = randi(365,8760,1);
veic = randi(333,8760,1);
max_veic = max(veic);
veicN = veic./max_veic;
A = randi(,27,1);
cHRA = cosd(HRA);
sHRA = sind(HRA);
sdecl = sind(decl);
cdecl = cosd(decl);
slat = sind(lat);
clat = cosd(lat);
pares_opt = fminsearch(@fun, randi([0,90],27,2))
function RMSE = fun(pares)
if any(pares( : )<0)|| any(pares( : ) >90)
RMSE = inf;
cinclin = cosd(pares(:,1))';
sinclin = sind(pares(:,1))';
cazim = cosd(pares(:,2))';
sazim = sind(pares(:,2))';
sdecl *(slat * cinclin - clat * sinclin .* cazim)...
+(cdecl .* cHRA)*(clat * cinclin + slat * sinclin .* cazim)...
+(cdecl .* sHRA)*(sinclin .* sazim));
max_Gparque = max(Gparque);
RMSE = sqrt(mean((GparqueN-veicN).^2));
My main goal is to achieve the best 'RMSE' possible, to do so I have to create a matrix ('pares') where each line contains a pair of values (one value from each column).These values have to be within a certain range(0-90). With each of this 27 pairs I have to calculate 'Ii'/'Gi'/'Di', giving me a matrix with a size like 8760*27.
Then I make a sum of 'Gi' to have 'Gparque'(vector 8760*1) and finally I calculate 'RMSE'. When I have RMSE calculated, I have to modify the matrix 'pares' to other values that can result in a better RMSE. Once there are many combinations of 27 values that can be within the 0-90 range, I have to get a solution that can optimize this search for the minimum RMSE. So, I need to use something that changes the values of 'pares' but with some optimization criteria that can approximate the minimum of RMSE.
I've searched and found that Genetic Algorithm tools in Matlab can be a good match for this problem. But now I don't know how I can introduce my data in this algorithm. I think that my matrix 'pares' is the individual that I want to optimize, and maybe it is easier to make this matrix a single vector because if I do so, each row of the matrix's used on GA could be an individual. But I am not sure of this!
Thank you so much!