Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how do i have a nonlinear constraint function with more than one input?

Subject: how do i have a nonlinear constraint function with more than one input?

From: Shen

Date: 4 May, 2009 22:31:01

Message: 1 of 2

I was wondering if the nonlinear constraint function to be passed to fmincon can have more than one input. By that, I mean in addition to the state variables, the constraint function also takes in a constant parameter that might change depending on what I want.

Basically, something like this:


[p, fval] = fmincon(@objectiveP,r1,p0,A,b,Aeq,beq,lb,ub,@nonlinearconstraintsP,r1)

and the objectiveP.m is as such:

function pfunction = objectiveP(p, r1, lambda)
...
where r1 and lamdba are constant inputs.

function [cineq ceq] = nonlinearconstraintsP(p, r1)
...
where r1 is a constant input.

Subject: how do i have a nonlinear constraint function with more than one input?

From: John D'Errico

Date: 4 May, 2009 22:49:02

Message: 2 of 2

"Shen " <shenge86@yahoo.com> wrote in message <gtnqb5$34p$1@fred.mathworks.com>...
> I was wondering if the nonlinear constraint function to be passed to fmincon can have more than one input. By that, I mean in addition to the state variables, the constraint function also takes in a constant parameter that might change depending on what I want.
>
> Basically, something like this:
>
>
> [p, fval] = fmincon(@objectiveP,r1,p0,A,b,Aeq,beq,lb,ub,@nonlinearconstraintsP,r1)
>
> and the objectiveP.m is as such:
>
> function pfunction = objectiveP(p, r1, lambda)
> ...
> where r1 and lamdba are constant inputs.
>
> function [cineq ceq] = nonlinearconstraintsP(p, r1)
> ...
> where r1 is a constant input.

Which variable are you optimizing over? P? Why
have you made the second argument to fmincon r1?
You cannot simply pass in extra arguments in random
places to fmincon.

Use an anonymous function.

[p, fval] = fmincon(@(P) objectiveP(p,r1,lambda),p0, ...
     A,b,Aeq,beq,lb,ub,@(P) nonlinearconstraintsP(P,r1,lambda));

John

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us