I am trying to solve system of nonlinear equations with fsolve.
The variables are x1 x2, x3, x4,,,,,,,,xi. The solutions should have decreasing values as i increases: Overall shape of xi should have trend of y=1/x with maximum value of x1 (i=1). x1 is order of 10(-6). Since xis are the concentrations, they should be positive or zero.
Trial runs give the values of positive and negative values after final iteration. Since the final set of solutions contains negative values for some xis, those should be discarded. The substitution of xi to sqrt(pi) with xi gives solutions of complex numbers for some xis.
I wonder whether there is any way to use a constraint in implementing fsolve. If I can use constraint such as xi>=0 or xi for real number during the iteration, it would give reasonable solutions.
Any comment would be appreciated.
You could rewrite the equations you're trying to solve with the change of variables xi=ai^2. Solving for ai will result in nonnegative corresponding values for ai^2=xi.
Alternatively, you could just solve using lsqnonlin() and impose positivity bounds explicitly.
I already tried ai^2=xi but this second trial gave oscillating solutions.
I wonder whether lsqnonlin can be used to solve my system. The solution will not fit any curve or formula. The reason for mentioning y=1/x is to explain decreasing xi for increasing i.
Solve the nonlinear system of equations as an optimization problem. I have used this to solve nonlinear equations with multiple solutions where a particular solution set (such as all non-negative) is required.
Min SSE=sum(fi^2)
Constraints : -xi<=0
fi are the nonlinear equations
xi are the non-negative variables
SSE is the error function, SSE>=0.
If equations are satisfied SSE will be zero.
Hence solution to minimization problem is the solution to the system of equations.
If your fi are differentiable, use fmincon.
However if your system of equations is not smooth, use Genetic Algorithm.
Good luck !
Ravi
"Don " <dong...@yahoo.com> wrote in message <hvokt0$rqc$1...@fred.mathworks.com>...
I looked up my Matlab. Mine is Release-14 and does not have SSE (curve fitting toolbox).
I should try other ways as you suggested.
"Ravi " <soni...@yahoo.com.thisisjunkremoveit> wrote in message <hvpa8t$o4s$1...@fred.mathworks.com>...
What do you mean by "oscillating solutions" ?
Do you mean that x1 >= x2 >= x3 ... is not satisfied
for the final solution you got from fsolve ?
Does the final solution you obtained by this
substitution satisfy your nonlinear system of equations ?
Or did fsolve just quit because the maximum number
of iterations were exceeded ?
> I wonder whether lsqnonlin can be used to solve my
> system. The solution will not fit any curve or
> formula. The reason for mentioning y=1/x is to
> explain decreasing xi for increasing i.
Best wishes
Torsten.
Torsten Hennig <Torsten...@umsicht.fhg.de> wrote in message <1986808344.7278.12772...@gallium.mathforum.org>...
You could try again the substitution x_i = (y_i)^2
and add new equations to your system:
x_1 - x_2 = (z_1)^2
x_2 - x_3 = (z_2)^2
..
x_(n-1) - x_n = z_(n-1)^2
with new variables z_1,...,z_(n-1).
If this system has a solution, it will automatically
satisfy x_1 >= x_2 ... >= x_(n-1) >= x_n.
Best wishes
Torsten.
SSE is not a MATLAB function. It is just an acronym for "Sum of Squares Error" which is obtained from the n equations.
SSE=sum(fi^2) =f1^2 + f2^2 + f3^2 + ... + fn^2
f1, f2, ..., fn are the n nonlinear equations
So you set up the optimization problem as
Min SSE
Constraints : -xi<=0
When SSE is minimized to zero, it means the equations are solved with all postive xi.
Ravi
Torsten Hennig <Torsten...@umsicht.fhg.de> wrote in message <738784316.7897.127720...@gallium.mathforum.org>...
You can specify constraints in the optimization to guide the solution.
Min SSE
Constraints :
-xi<=0 positive constraint
xi-xi-1<=0 x1<xi-1 constraint
Ravi
"Ravi " <soni...@yahoo.com.thisisjunkremoveit> wrote in message <hvuje0$874$1...@fred.mathworks.com>...