MATLAB: How to make sure that fsolve gives only positive values as the solution

fsolvepositive solution

I have L equations to solve. I am using the following code to solve :
fh = matlabFunction([equn(1:L)],'vars',{[lam(1:L)]});
options = optimset('Display','off','TolFun',eps);
[solu_fsolve,value] = fsolve(fh, [1:L] ,options ) ;
But, i am getting -ve answer as a solution of fsolve. But, i am expecting + ve solutions only. Is there anyway to make sure that fsolve gives only +ve solutions?
Please answer. Thanks in advance.
With best regards, kalpana

Best Answer

Square your unknowns in the functions you supply to fsolve.
E.g. if you want to solve
x(1)-5=0,
solve instead
y(1)^2-5=0.
After you get the solution y(1) from fsolve (in this case sqrt(5)), you only have to square it to get x(1) (in this case 5) - the solution of your original untransformed problem.
Best wishes
Torsten.