**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# Limit on the change rate of the variable in fmincon function

10 views (last 30 days)

Show older comments

### Accepted Answer

Matt J
on 12 Nov 2019

Edited: Matt J
on 12 Nov 2019

You would build linear inequality matrices like the following.

E=diff(eye(numel(u)));

A=[E;-E]; b=[ub(:);-lb(:)]; %linear inequality matrices

##### 21 Comments

Walter Roberson
on 13 Nov 2019

Is u the function being minimized, which would have to be a scalar for each point? Or is u the inputs to that function, which could be a vector? Is the question about the rate of change of the signal a question about the values of all of the elements of the Jacobian, that all of the partial derivatives are within the same lb ub pair? Is the question about the difference between adjacent locations that fmincon is permitted to examine?

Because what this proposed formulation seems to accomplish is to limit the difference between adjacent input variables, like saying in f = x^2 - y^2 as an objective function that lb <= x-y <= ub, which is not what I would understand as the rate change of a signal.

Walter Roberson
on 13 Nov 2019

Mohammad
on 13 Nov 2019

Matt J
on 13 Nov 2019

Catalytic
on 13 Nov 2019

Edited: Matt J
on 13 Nov 2019

You should not tell fmincon that a constraint is nonlinear when it is, in fact, linear.

The one exception to this that I can think of is when it is more computationally manageable to represent the operation A*x in operator form, similar to what pcg allows you to do. But here, I don't see any reason to do that. Note that Matt J's A,b matrices can also be constructed in sparse form if memory limits are a problem.

E=diff(speye(numel(u)));

A=[E;-E]; b=[ub(:);-lb(:)]; %linear inequality matrices

Matt J
on 13 Nov 2019

Edited: Matt J
on 13 Nov 2019

Basically, diff(u) is not something multiplied by the variable u.

Yes, it is. E*u is the same as diff(u). That is why my original proposal is valid.

>> u=rand(5,1);

>> E=diff(speye(5));

>> E*u

ans =

-0.3930

0.2690

0.0212

0.4964

>> diff(u)

ans =

-0.3930

0.2690

0.0212

0.4964

Mohammad
on 13 Nov 2019

Walter Roberson
on 13 Nov 2019

Matt J
on 13 Nov 2019

You don't need u beforehand. You just need to know the number of unknowns, N

E=diff(speye(N));

Mohammad
on 13 Nov 2019

Edited: Mohammad
on 13 Nov 2019

@Walter and Matt: u is a vector in each sampling time t. I want to bound the slew rate of this vector ovet time, i.e., I want u(t+1) - u(t) to lie between two bounds. I don't want to put bounds on the difference of the entries of u.

Hence, I see that none of the diff(u) nor E*u don't refer to what I want which is the slew rate of the vector u ( u(t+1) - u(t) ).

Is there a way, probably defining non-linear constraint to get that?

Walter Roberson
on 13 Nov 2019

Is it correct that you have a function of a single variable?

fmincon evaluates the function with different values of the input variables. fmincon cannot know ahead of time what response there will be to the different inputs, so it cannot guarantee that on two adjacent calls that the function response will change only within certain bounds no matter what the step size is. But if you want to constrain the difference between values of the design variables that are to be attempted, then you can configure https://www.mathworks.com/help/optim/ug/fmincon.html#busog7r-options DiffMaxChange DiffMinChange FiniteDifferenceStepSize

I still think that what you really want is limits on the derivative(s) of the function at function at the location to be evaluated. If I am correct then except for functions that are at most quadratic, you would need to implement this through nonlinear constraints that know how to evaluate the derivative of the function.

Matt J
on 13 Nov 2019

Edited: Matt J
on 13 Nov 2019

Is there a way, probably defining non-linear constraint to get that?

This is still a linear constraint!

I will assume that your total matrix of unknown variables is MxN and is of the form

U=[u(1, u(2),...,u(N)]

where each u(t) is an Mx1 vector. I will assume, similarly that you have Mx(N-1) matrices LB and UB of lower and upper bounds, respectively. Then the appropriate linear inequality matrices are

E=kron(diff(speye(N)), speye(M));

A=[E;-E]

b=[UB(:);-LB(:)];

Mohammad
on 14 Nov 2019

Matt J
on 14 Nov 2019

Edited: Matt J
on 14 Nov 2019

It sounds like you're saying that at time u(t), the values of u(t-1) are already known. Then the bounds can be rewritten

lbnew <= u(t) <= ubnew

where lbnew and ubnew are the known bound vectors

ubnew=ub+u(t-1);

lbnew=lb+u(t-1);

They are known since u(t-1) is known. So, you now have plain ordinary bounds on u(t) and there is nothing special about the way you set up the problem.

But I need to emphasize that, if you have an objective f(t,u(t)) at each time t, the approach you are pursuing will not give you the minimum of if that was your goal in all this. There is no way to do that by solving an independent problem at each t.

### More Answers (1)

### See Also

### Categories

### Tags

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)