MATLAB: How to solve a system of equations with a constraint

constraintfsolvelsqnonlinsystem equations

Hello, I'm new to MATLAB and I'm looking for a way to solve the system below:
w=lambda^(-1)*covmat^(-1)*(meanbl-(vec1'*covmat^(-1)*vec1)^(-1)*(vec1'*covmat^(-1)*meanbl-lambda)*vec1)
H=w'*meanbl+phi*sqrt(w'*covmat*w)
Where I want to find w (n-element vector) and phi (scalar). The constraint is that all the elements of w and also phi have to be positive. lambda and H are scalars, covmat is a nxn matrix, and meanbl and vec1 are n-element vectors.
I'm aware that fsolve does not allow for constraints, but I'm not being able to use lsqnonlin.
Thank you very much.

Best Answer

Instead of w and phi, use w.^2 and phi^2 in your system.
This ensures that the unknowns are nonnegative.
Best wishes
Torsten.