Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Constraint in Implementing fsolve.m

319 views
Skip to first unread message

Don

unread,
Jun 21, 2010, 4:43:24 PM6/21/10
to
Hi,

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.

Matt J

unread,
Jun 21, 2010, 4:55:20 PM6/21/10
to
"Don " <dong...@yahoo.com> wrote in message <hvoitc$jrt$1...@fred.mathworks.com>...


> 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.

Don

unread,
Jun 21, 2010, 5:17:20 PM6/21/10
to
"Matt J " <mattja...@THISieee.spam> wrote in message <hvojjo$5db$1...@fred.mathworks.com>...

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.

Ravi

unread,
Jun 21, 2010, 11:22:05 PM6/21/10
to
Hi Don,

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>...

Don

unread,
Jun 22, 2010, 5:30:26 AM6/22/10
to
Thanks Ravi,

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>...

Torsten Hennig

unread,
Jun 22, 2010, 6:18:42 AM6/22/10
to
> "Matt J " <mattja...@THISieee.spam> wrote in
> message <hvojjo$5db$1...@fred.mathworks.com>...
> > "Don " <dong...@yahoo.com> wrote in message
> <hvoitc$jrt$1...@fred.mathworks.com>...
> >
> > > 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.

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.

Don

unread,
Jun 22, 2010, 7:44:06 AM6/22/10
to
Thank you.
Oscillating solution means the values of solutions are 2, 0, 4, 1, 3, .5, etc., the overall trend of which do not satisfy the final solution that should be.
I set the tolerance and the tolerance I achieved are within the limit: satisfies the required tolerance. I tried three ways to solve the system: Original system gives negative values for some solutions, substitution of xi with sqrt(yi), gives complex numbers for some solutions and substitution of xi with yi^2 gives oscillating solution as I mentioned here. All trials satisfy the tolerance limit and final solutions can be obtained within 20 iterations.

Torsten Hennig <Torsten...@umsicht.fhg.de> wrote in message <1986808344.7278.12772...@gallium.mathforum.org>...

Torsten Hennig

unread,
Jun 22, 2010, 8:10:27 AM6/22/10
to
> Thank you.
> Oscillating solution means the values of solutions
> are 2, 0, 4, 1, 3, .5, etc., the overall trend of
> which do not satisfy the final solution that should
> be.
> I set the tolerance and the tolerance I achieved are
> within the limit: satisfies the required tolerance. I
> tried three ways to solve the system: Original system
> gives negative values for some solutions,
> substitution of xi with sqrt(yi), gives complex
> numbers for some solutions and substitution of xi
> with yi^2 gives oscillating solution as I mentioned
> here. All trials satisfy the tolerance limit and
> final solutions can be obtained within 20 iterations.
>
>

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.

Ravi

unread,
Jun 23, 2010, 11:29:04 PM6/23/10
to
Hi Don,

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>...

Ravi

unread,
Jun 23, 2010, 11:41:04 PM6/23/10
to
Also if you are getting solutions that satisfy the equations but do not represent your physical solution, it means the system of equations has multiple solutions (which nonlinear equations can have).

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>...

0 new messages