COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### FSolve With Constraints

• Follow

```So let's say I have some vector w and some function f(u) that can produce a vector w. I want to choose u such that w-f(u)=0. This works easily enough in fsolve.

However, if I want to place a constraint on u, so that maybe u(5)=x, then I can't figure out a way to do that in fsolve. The only thing I've been able to think of is to instead use fmincon with sum((w-f(u)).^2) or (w-f(u)'*(w-f(u)) as the objective function since that will let me have more influence on the constraints.

Any thoughts on a better method or is it possible to incorporate constraints into fsolve?
```
 0

```"ss4johnny Hall" <ss4johnny@hotmail.com> wrote in message <i9so37\$dtj\$1@fred.mathworks.com>...
> So let's say I have some vector w and some function f(u) that can produce a vector w. I want to choose u such that w-f(u)=0. This works easily enough in fsolve.
>
> However, if I want to place a constraint on u, so that maybe u(5)=x,

Well, constraints of this kind are easy to handle. Just rewrite the function with u(5) fixed.

g=@(u) f([u(1:4) , x , u(6:end)])

and then solve w-g(u)=0.
```
 0

```"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <i9sok3\$i2m\$1@fred.mathworks.com>...
> "ss4johnny Hall" <ss4johnny@hotmail.com> wrote in message <i9so37\$dtj\$1@fred.mathworks.com>...
> > So let's say I have some vector w and some function f(u) that can produce a vector w. I want to choose u such that w-f(u)=0. This works easily enough in fsolve.
> >
> > However, if I want to place a constraint on u, so that maybe u(5)=x,
>
> Well, constraints of this kind are easy to handle. Just rewrite the function with u(5) fixed.
>
> g=@(u) f([u(1:4) , x , u(6:end)])
>
> and then solve w-g(u)=0.

Thanks, that seems pretty obvious now that I think about it.
```
 0

2 Replies
395 Views

Similiar Articles:

7/26/2012 12:46:31 PM