Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Constrained non linear system, fmincon: User supplied objective
function must return a scalar value.

Replies: 1   Last Post: Feb 12, 2013 1:13 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Alan Weiss

Posts: 1,261
Registered: 11/27/08
Re: Constrained non linear system, fmincon: User supplied objective
function must return a scalar value.

Posted: Feb 12, 2013 1:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/12/2013 12:44 PM, Pl Pl wrote:
> Hi all,
>
> I have a non linear differential equation:
>
> dm(1) = f1(m(1),m(2),m(3))
> dm(2) = f2(m(1),m(2),m(3))
> dm(3) = f3(m(1),m(2),m(3))
>
> whose solutions must lie on the unit sphere. I'm trying to compute the
> fixed points of the system so I have to solve the system:
>
> f1(m(1),m(2),m(3)) = 0
> f2(m(1),m(2),m(3)) = 0
> f3(m(1),m(2),m(3)) = 0
>
> I first tried to use fsolve but this gave irrelevant solutions, not
> even lying on the unit sphere. I then tried to use fmincon by
> squaring my dm-vector so that it becomes positive. Here is what my
> code looks like:
>
> Differential equation:
>
> function dm = llgfix(t,m,param)
> dm = zeros(3,1);
>
> dm(1) = f1(m(1),m(2),m(3));
> dm(2) = f2(m(1),m(2),m(3));
> dm(3) = f3(m(1),m(2),m(3));
>
> dm = dm.^2;
> end
>
> Constraints:
>
> function [c, ceq] = unitsphere(x)
> c = [];
> ceq = x(1)^2 + x(2)^2 + x(3)^2 - 1;
>
> Minimisation:
>
> m0 = rand(1,3);
> options = optimset('Display','iter','Algorithm','active-set');
> fix =
> fmincon(@llgfix,m0./norm(m0),[],[],[],[],[],[],@unitsphere,options)
>
> However, when running the code, I always get the same error:
>
> Error using fmincon (line 674)
> User supplied objective function must return a scalar value.
>
> and I can't figure out why, does anybody have an idea?
> Thanks in advance!


Your function llgfix returns a three-element vector instead of a scalar.
The objective function for fmincon must be a scalar, just as the error
message states.

Alan Weiss
MATLAB mathematical toolbox documentation



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.