Minimization of values between 2 functions using optimization toolbox

Hello everyone,
I have a function, let's call it velopt, that represents the velocity at every point in a flow field. This function, velopt, works by using point forces in the flow field to create "moving" flow and these forces have 2 inputs: location in the flow field and magnitude. For this problem my variables are the magnitude, the location is fixed.
I want velopt to emulate some experimental data I have. What I am doing is minimizing the value between velopt in 4 directions and my experimental data at those same directions with the magnitude variables for 4 directions.
I am running into some unexpected results and I am not sure what is happening.
1 - At first I am just using the diference between the right side and minimizing that. Clearly something isn't right because this is not the best fit. Additionally the model function never goes above the experiments, which is sort of weird because the error would be reduced at some points if it did.
2 - I get different values for my written fmincon function and the global search function.
Here is the code
xx = [1.5, 1.5, -0.5,0.4, 0.4]; % X Location of forces
yy = [-3, 3, 0,1.25, -1.25]; % Y Location of forces
pfl = [0, 0]; %Location of the potential flow [x y]
Here I load data from the model
load('model01.mat')
r = 0.2147; %1 R = 0.2147 mm
Dist01 = Dist_A_mm01./r; %Dimensionless distance, R
ydir = 0;
xdir = 0;
Then I calculate the value of the function velopt to use in the cost function
simply_velo_am = @(sf_arg) velopt(Dist01(9:20),ydir,sf_arg,xx,yy,sf_arg(:,6),pfl); %Values in the anterior
simply_velo_pm = @(sf_arg) velopt(-Dist01(10:43),ydir,sf_arg,xx,yy,sf_arg(:,6),pfl);%Values in the posterior
simply_velo_rm = @(sf_arg) velopt(xdir,-Dist01(6:25),sf_arg,xx,yy,sf_arg(:,6),pfl);%Values on the right
simply_velo_lm = @(sf_arg) velopt(xdir,Dist01(6:25),sf_arg,xx,yy,sf_arg(:,6),pfl);%Values on the left
Function to minimize, where model_right01_m are the experimental values
ff = @(sf_arg) nan_norm((( Model_Right01_m(6:25) - simply_velo_rm(sf_arg))/Model_Right01_m(6:25))); %relative error
Then I have some constraints
sf_ini = [1 ,1, 2, -2, -2, 2]; %initial guess for variables
A = [0 0 0 1 0 0; 0 0 0 0 1 0; -1 -1 0 0 0 0; 0 0 0 0 0 -1; 0 0 -1 0 0 0]; %A*x < b
b = [0; 0; 0; 0;0]; % b = ()
Aeq = [1 -1 0 0 0 0; 0 2 -1 0 0 0; 0 0 0 -1 1 0; 1 1 1 1 1 0]; %Aeq *x = beq
beq = [0 0 0 0]; %beq
and then I use the brute force method to find a good solution
fval_min = 1e10;
for i = 1 : 19
sf_ini = 100*rand(size(sf_ini)) - 50
% options = optimset('Display', 'iter', 'MaxFunEvals', 600,'PlotFcns',@optimplotfval,'TolFun',1e-4,'TolX',1e-4);
options = optimset('MaxFunEvals', 6000,'TolFun',1e-12,'TolX',1e-12);
[fm, fval] = fmincon(ff,sf_ini,A,b, Aeq, beq,[],[],[],options); %f min search
fval
if (fval < fval_min)
saved_fm = fm;
fval_min = fval;
end
fm
end
saved_fm
I also tried the GlobalSearch
gs = GlobalSearch('Display','iter');
problem = createOptimProblem('fmincon','x0',sf_ini,'objective',ff,'Aineq',A,'bineq',b,'Aeq',Aeq,'beq',beq);
soln = run(gs,problem)
I am not sure what's wrong and why I don't get the minimization correctly. Any help or suggestions would be thoroughly appreciated.

Respuestas (0)

Categorías

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by