0

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?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Akshay
  • 3
  • 2
  • [`fminsearch`](https://www.mathworks.com/help/matlab/ref/fminsearch.html) does not require a scalar value as an **input**; see [this](https://stackoverflow.com/a/57081470/8239061). However, it does require a scalar **output**. From the documentation: "*f(x) is a function that returns a scalar, and x is a vector or a matrix*." – SecretAgentMan Jul 24 '19 at 20:02
  • Is there a mathematical presentation of this? You're minimizing the minimum of a maximum? Do the values of `a1,...a6` or `x1` depend on the value of `a0`? – SecretAgentMan Jul 24 '19 at 20:04
  • there is no mathematical representation of this. yes the values a1,....a6 dependent on a0. – Akshay Jul 25 '19 at 12:31
  • Are you getting an error? Can you [edit] your question to include this equation you mention as well as your output from `fminsearch()`? – SecretAgentMan Jul 25 '19 at 13:51
  • Some possible code errors: `a1 = 1.329e-05` with no space before the "**e**" and there seems to be an extra "**)**" at the end of your function handle, `f`. Even with that removed, `f(0)` gives an error so it will need to be vectorized for use with `fminsearch` (unless I'm missing something) by replacing all `^` with `.^`. – SecretAgentMan Jul 25 '19 at 15:53
  • Your `f` appears to be a function of only `ao`, is that right? It conflicts with your question title. Just to confirm, you are looking for the value of `a0` which minimizes `f`? (this is the interpretation for `a0_min = fminsearch(f,0)`) – SecretAgentMan Jul 25 '19 at 18:12

1 Answers1

0

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.

  • Change a1 = 1.329 e-05; to a1 = 1.329e-05;.
  • Change ^ to .^ in f unless there's a reason not too.
  • Remove extra ) 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.

Graph showing objective function constant over domain.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
  • Thank you for the answer. By change ^ to .^, i am getting minimum of a0. I did check it for different set of values and it works. – Akshay Jul 26 '19 at 05:50