I have an equation with a number of variables. I have to find minimum of variable a0
, by giving the input to all other variables [a1, a2, a3, a4, a5, a6, x1]
.
x1
is an array and the other variables are constant for a constant a0 value. (The other 6 variables vary with changes in the value for a0
, but right now I am just considering a0 = 0
, so that the six variables have constant values mentioned below 'for the purpose of learning'.)
I tried giving array values to each variable at the same time to be included in the function, but it did not work as fminsearch
takes a scalar value I suppose.
a0 = 0;
x1 = -10:0.1:10;
a1 = 1.329438561310570 e-05;
a2 = -0.002504562092133;
a3 = -0.036785455629072;
a4 = 0.056797862719813;
a5 = 2.624845095825030;
a6 = 30.072580030528270;
f=@(a0) min(((max((((30*a0*(x1.^4))+(20*a1*(x1.^3))+(12*a2*(x1.^2))+.....(6*a3*x1)+(2*a4))/((1+((6*a0*(x1.^5))+(5*a1*(x1.^4))+(4*a2*(x1.^3))+(3*a3*(x1.^2))+(2*a4*(x1))+(a5))^2))^1.5)))-0.1)+(-0.1-(min((((30*a0*(x1.^4))+(20*a1*(x1.^3))+(12*a2*(x1.^2))+(6*a3*(x1))+(2*a4))/((1+((6*a0*(x1.^5))+(5*a1*(x1.^4))+(4*a2*(x1.^3))+(3*a3*(x1.^2))+(2*a4*(x1))+(a5))^2))^1.5)))));
a0_min = fminsearch(f,0);
I am assuming I will get a0
minimum in the range of 10^-7 or 10^-6. Not completely sure. Am I giving the input for function as correct values?
tl;dr
Typos in your example. Code doesn't run. Optimizing is minimizing an objective function over a domain and definitely has a mathematical representation. Your objective function appears to a constant relative to a0
which indicates something in the example (data, or f
) might be wrong.
The example contains some typographical errors.
a1 = 1.329 e-05;
to a1 = 1.329e-05;
.^
to .^
in f
unless there's a reason not too. )
at right end of f
. The objective function is constant relative to a0
.
% MATLAB 2018b
x1 = -10:0.1:10;
a1 = 1.329e-05;
a2 = -0.003;
a3 = -0.037;
a4 = 0.057;
a5 = 2.625;
a6 = 30.073;
with
f=@(a0) min(((max((((30*a0*(x1.^4))+(20*a1*(x1.^3))+(12*a2*(x1.^2))+6*a3*x1)+(2*a4))/((1+((6*a0*(x1.^5))+(5*a1*(x1.^4))+(4*a2*(x1.^3))+(3*a3*(x1.^2))+(2*a4*(x1))+(a5)).^2)).^1.5)))-0.1)+(-0.1-(min((((30*a0*(x1.^4))+(20*a1*(x1.^3))+(12*a2*(x1.^2))+(6*a3*(x1))+(2*a4))/((1+((6*a0*(x1.^5))+(5*a1*(x1.^4))+(4*a2*(x1.^3))+(3*a3*(x1.^2))+(2*a4*(x1))+(a5)).^2)).^1.5))));
This code
a0init = 0; % Initial guess for a0
[a0star, f_min] = fminsearch(f,a0init)
executes but the initial guess has no impact on the objective function. For example, try [a0star, f_min] = fminsearch(f,-2)
.
Evaluation of f(a0)
for multiple values of a0
reveals a deeper problem. There is nothing to minimize and any value of a0
seems to be just as good.