# Model Predictive Controller only works for certain values

**URL:** <https://discourse.julialang.org/t/model-predictive-controller-only-works-for-certain-values/51916>\
**Category:** Optimization (Mathematical)\
**Tags:** optimization\
**Created:** [December 16, 2020, 7:46am UTC](https://discourse.julialang.org/t/model-predictive-controller-only-works-for-certain-values/51916 "2020-12-16T07:46:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 16, 2020, 7:52pm UTC](https://discourse.julialang.org/t/model-predictive-controller-only-works-for-certain-values/51916/3 "2020-12-16T19:52:34Z")

</div>

I can’t reproduce your issues, because I don’t know the arguments to your function. Take a read of: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

Some things that might help:

- use `fix(phi[1] init_phi)` instead of adding the initial value constraints.
- Add sensible bounds on `phi`, `theta`, and `u`
- Consider rewriting `phi` and `theta` as a `@NLexpression` instead of a variable. (It seems your only real decision variable is `u`.) For example, something like:

```nohighlight
phi = [@NLexpression(model, init_phi)]
for i in 2:num_time_steps
    push!(phi, @NLexpression(model, phidot[i - 1] * h + phi[i - 1]))
end

```

---

_[View the full topic](https://discourse.julialang.org/t/model-predictive-controller-only-works-for-certain-values/51916)._
