Quantcast
Channel: MATLAB Central Newsreader - tag:"optimization"
Viewing all articles
Browse latest Browse all 130

Re: How can a constrained function in an objective function be used with fmincon in maltab?

$
0
0


"Dirk Kurt" <stranger00@gmail.com> wrote in message
news:mt3ltj$cpq$1@newscl01ah.mathworks.com...
> The below given constrained function is used in the objective function
> that is going to be minimized by using fmincon.
>
> fun=@(x) 2*(1-x)*(0.5<=x)*(x<=1)
>
> The objective function is
>
> obj =(c(i).*x(i)+b(i).*quad(fun,l,u))
>
> Due to the function defined in the corresponding interval I get the error:
>
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
>
> Error in ==> @(x)2*(1-x)*(0.5<=x)*(x<=1)
>
>
> Caused by:
> Failure in initial user-supplied objective
> function evaluation. FMINCON cannot continue

The * operator performs MATRIX multiplication.
The .* operator performs ELEMENTWISE multiplication.

Since QUAD calls your function with a vector as input, you want to use
elementwise multiplication.

But a couple of additional comments:

1) Don't do the "masking" inside your integrand function fun to limit the
ranges of x over which you're integrating. Change the limits of integration
l and u: max(l, 0.5) and min(u, 1).
2) Consider using INTEGRAL instead of QUAD.
3) If the contents of fun are fixed, i.e. that function isn't going to
change, perform the integration yourself rather than calling QUAD and plug
in the analytical expression. Integrating 2-2*x is a Calculus 1 problem.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Viewing all articles
Browse latest Browse all 130

Trending Articles