help-octave
[Top][All Lists]

## Re: limiting the range of solutions with fsolve

 From: Bob Walton Subject: Re: limiting the range of solutions with fsolve Date: Thu, 1 Nov 2012 11:55:01 -0700 (PDT)

```wwwups wrote
> ...
> This might be a dumb question, but how does one add penalties to the
> objective function? Are you modifying the tolerances using structures?
> ...

If I understand fsolve correctly, it attempts to solve the system:

f1(x1,x2,x3)=0
f2(x1,x2,x3)=0
f3(x1,x2,x3)=0

with no other constraints on x1, x2 or x3.  One can add three more
functions:

f4(x1,x2,x3)=0
f5(x1,x2,x3)=0
f6(x1,x2,x3)=0

where:

f4(x1,x2,x3)=1e6*max(abs(x1)-1),0)^4
f5(x1,x2,x3)=1e6*max(abs(x2)-1),0)^4
f6(x1,x2,x3)=1e6*max(abs(x3)-1),0)^4

Here is a sample objective function:

function obj=testfsolve(p)
x1=p(1);
x2=p(2);
x3=p(3);
f1=3*x1+4*x2+5*x3+1;
f2=-2*x1+3*x2-2*x3-4;
f3=2*x1-6*x2+x3+3;
f4=1e6*max(abs(x1)-1,0)^4;
f5=1e6*max(abs(x2)-1,0)^4;
f6=1e6*max(abs(x3)-1,0)^4;
%f4=0;f5=0;f6=0; %uncomment for unconstrained solution
obj=[f1 f2 f3 f4 f5 f6];

To run:

[p,f]=fsolve('testfsolve',[0 0 0])

Is that the right answer for the constrained problem?  I doubt it, because
the function is linear and the solution isn't at or near a corner of the
constraints.  But it did keep the parameters pretty much in the range -1 to
1.

If you were using a minimizer like fminsearch, there is only one objective
function, and one would simply add the parameter bounds functions to it.
For fminsearch, one could use:

obj=sum(obj.*obj);

at the end of the above function.  Interestingly enough, that gives about
the same result as fsolve, particularly if one sets the simplex tolerance
small (1e-8).
--
Bob Walton

--
View this message in context:
http://octave.1599824.n4.nabble.com/limiting-the-range-of-solutions-with-fsolve-tp4645953p4645994.html
Sent from the Octave - General mailing list archive at Nabble.com.

```