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

fsolve problems

105 views
Skip to first unread message

Jacob McFarland

unread,
Mar 23, 2008, 4:28:02 PM3/23/08
to
Hello,
Let me start by saying im a pretty basic user for matlab.
Im no beginer but definately not a professional.
I am trying to solve a nonlinear system of equations for a
combustion problem. I need to know if there is a way to
force fsolve to only look for real roots. It is unable to
find an answer so far but it always moves into complex
numbers. The roots will not be complex or negative if they
actually exist. Can someone tell me if i can limit the
roots it looks for to only real positive numbers?
Also how many itterations should i allow it to use? I am in
the realm of 1e6 for itterations and function evaluations.
This does not take too long on my computer but it doesnt
seem to help it find any better of a solution.
Thanks,
- Jacob

Miroslav Balda

unread,
Mar 23, 2008, 7:08:01 PM3/23/08
to
"Jacob McFarland" <jacob.a....@gmail.com> wrote in
message <fs6egh$98h$1...@fred.mathworks.com>...

Hi Jacob
I see that nobody, who has the Optimization Toolbox answers.
I may not help you with fsolve, which is in that toolbox,
because I don't have it, however, I could use my function
LMFnlsq.m from the File exchange (Id 17534). I thing that
the solution for fsolve could be similar:

x = LMFnlsq('eqns',x0);

Build a function which evaluates f_i(x), 1<=i<=n to be zero:

function f = eqns(x)

f = [expression for the 1st equation
expression for the 2nd equation
:
expression for the nth equation
imag(x).*w1
(x<0).*x.*w2
];
x is a column vextor, w1, w2 are big enough (1e4?) scalar
weights or columns of vector weights.
I hope it helps.

Mira


John D'Errico

unread,
Mar 23, 2008, 11:07:01 PM3/23/08
to
"Miroslav Balda" <mirosla...@balda.cz> wrote in message
<fs6nsh$hur$1...@fred.mathworks.com>...

> "Jacob McFarland" <jacob.a....@gmail.com> wrote in
> message <fs6egh$98h$1...@fred.mathworks.com>...
> > Hello,
> > Let me start by saying im a pretty basic user for matlab.
> > Im no beginer but definately not a professional.
> > I am trying to solve a nonlinear system of equations for a
> > combustion problem. I need to know if there is a way to
> > force fsolve to only look for real roots. It is unable to
> > find an answer so far but it always moves into complex
> > numbers. The roots will not be complex or negative if they
> > actually exist. Can someone tell me if i can limit the
> > roots it looks for to only real positive numbers?
> > Also how many itterations should i allow it to use? I am in
> > the realm of 1e6 for itterations and function evaluations.
> > This does not take too long on my computer but it doesnt
> > seem to help it find any better of a solution.
> > Thanks,
> > - Jacob
>
> Hi Jacob
> I see that nobody, who has the Optimization Toolbox answers.

Remember that this is over a weekend for those
who might respond, a holiday weekend at that.

The reason why your solutions are going complex
is typically due to a problem of domain. For
example, suppose your function has the variable
a. a is unconstrained, but inside the function
you take log(a). Suppose fsolve tries to evaluate
the objective for negative values of a. SURPRISE!
Complex numbers result. They "contaminate" the
arithmetic, and suddenly fsolve is working in the
complex domain.

One solution is to constrain your parameters.
While fsolve will not accept explicit constraints,
you can use a solver like lsqnonlin.

Alternatively, use a transformation of variables.
If you will compute log(a) inside your objective,
then use a transformation of the variable.

b = log(a)

or, more importantly,

a = exp(b)

Whereas a must be non-negative for happy
completion of fsolve, b is unconstrained.

HTH,
John

Jacob McFarland

unread,
Mar 24, 2008, 11:35:03 AM3/24/08
to
I will try variable substitution. The problem terms are
ones that are raised to the ^.25. I have tried lsqnonlin
with complex answers as well. I tried to constrain it using
upper and lower bounds but it still went complex and below
the lower bound. Dont know why...
Thanks,
Jacob
0 new messages