First Try

if (A <= 1e-04) & (A >= 4e-04)

fun = (1- (f(1))/500)^2 + (1- (f(2))/1800)^2;

fun = (1- (f(1))/500)^2 + (1- (f(2))/1800)^2 + 1e30 * ( (A - 4e-04).^2 + (A - 1e-04).^2 );

or second try

if (A(i) >= 1e-04) & (A(i) <= 4e-04)

fun(i) = (1- (f(1))/500)^2 + (1- (f(2))/1800)^2;

fun(i) = (1- (f(1))/500)^2 + (1- (f(2))/1800)^2 - 1e30 * ( (A(i) - 4e-04).^2 + (A(i) - 1e-04).^2 );

Hello,

I wrote above a piece of a code where fun is an objective function that I aim to minimize. And A, an array of size (1,13), is the optimization variable. f is also an array of size(1,13) and my aim is to tune its first two values f(1) and f(2) where the values of f depend on A. The ultimate goal is to optimize A such that f(1) and f(2) obtain the specific values 500 and 1800 respectively, and this has to be done by minimizing the value of objective fucntion where its return value is a scalar.

I needed to impose my conditions that if A lies outisde the specified boundaries then the value of the objective function function will decrease rapidly depending on the distance of this variable from the boundaries.

The displayed error in Matlab is "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-13." of the first try.

The second gave unlogical result.

I'm not knowing how to fix it.

Thank you.