I am trying to understand how the following code optimize the objective function.
I thought if I use vector as an input for fminsearch as below, the result 'Kp' should give me the point where the objective function is minimized.
For example, Kp[1] should give me the point where the objective function is minimized for given K[1] and Z[1]. So it is just solving univariate function.
But if I have the objective function as below. Kp[4] should also affect the Kp[1] because there is flipud(Vs) inside the function and vice versa.
And fminsearch still gives me the result without showing any error message.
If this is the case, what does exactly fminsearch minimize? Is Kp[1] still minimize the objective function for given K[1] and Z[1]?
Does fminsearch take this as a multivariate optimization problem instead of univariate in the case without flipud(Vs)?
If so, how does fminsearch minimze the objective function because then there are more than one equations to minimize in this case?
clear
clc
R = 1.008;
sig = 0.75;
tempkgrid = linspace(-2,6,2)';
K = [tempkgrid ; tempkgrid];
Z = [2*ones(2,1);4*ones(2,1)];
aconst1 = -2*ones(4,1);
aconst2 = 6*ones(4,1);
const = R * (K + Z);
obj = @(Vs) -((1/(1-1/sig)) * ((Z + K - Vs./R) > 0) .* (Z + K - Vs./R).^(1-1/sig) + flipud(Vs));
Kp = fminsearchbnd(@(c) norm(obj(c)) ,aconst1, aconst1, const);