Is there a way to use fsolve in MATLAB, specifying a bound for the solution? i.e. all solution variables > 0
A:
No. However, instead of solving for F(x)=0
, you can minimize abs(F(x))
using e.g. FMINBND.
EDIT
Unfortunately, fminbnd
does not seem to support array-valued arguments (which I assume is what you want). For this to work, you need to turn to FMINCON from the optimization toolbox.
Jonas
2010-08-27 01:32:08
+1
A:
Not directly, but one solution to this problem is to add a term to your equation which constrains your problem.
I don't have the optimization toolbox, so I can't give you a specific example using fsolve, but here's how I would do it with fminsearch, which has the same issue.
myFun = @(args) abs( sin(args(1)) + cos(args(2)) )
fminsearch(myFun, [0, 0])
ans =
-0.8520 0.7188
But if I want to constrain my problem to positive solutions
myFun = @(args) abs(sin(args(1)) + cos(args(2))) + (args(1)<0) + (args(2)<0)
fminsearch(myFun, [0, 0])
ans =
0.0000 1.5708
There should be a way to tweak your equation similarly to solve your problem.
Kena
2010-08-27 17:16:08