Use of fsolve

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Use of fsolve

Daniel Tourde-3
Hello,

I would like to use the fsolve solution for solving non-linear equations
where sometimes, solutions or constant are very small:

  y(1) = 12*((x(3)*x(1))/2)/E - nlcoef(3);
  y(2) = 12*((x(3)*x(2)+x(1)*x(4))/6)/E - nlcoef(4);
  y(3) = 12*((P*x(3)/2+x(4)*x(2)+x(1)*x(5))/12)/E - nlcoef(5);
  y(4) = 12*((P*x(4)/2+x(5)*x(2))/20)/E - nlcoef(6);
  y(5) = 12*((P*x(5))/60)/E - nlcoef(7);


Where some of my nlcoef values are very small (between 1e-7 and 1e-10).
It happens that the solutions given by fsolve can be wrong due to
rounding and precision errors.

It is possible to increase the tolerance of fsolve by using the
fsolve_options:

octave:1> fsolve_options

  *** fsolve_options:

  fsolve_options (KEYWORD, VALUE)

  Set or show options for fsolve.  Keywords may be abbreviated
  to the shortest match.

  Options for fsolve include:

    keyword                                  value
    -------                                  -----

    tolerance                                1.49012e-08

  octave:2> fsolve_options ("tol", 1e-12)
  octave:3> fsolve_options ("tol")
  ans =  1.0000e-12


I know the existence of some flags provided by fsolve:


Valid values and their meanings are:

  -2:  input error
  -1:  error encountered in user-supplied function
   1:  solution converged to requested tolerance
   4:  iteration limit exceeded
   3:  iteration is not making good progress



It happens during my computation that sometimes flag 3 or flag 4 are
raised. And of course, this is when I got wrong results.


Then my question is the following: How can I change the iteration limit
within fsolve. How can I improve the precision of Octave in its
globality ? In a word, what is the best way to get rid of flag 4 and
flag 3 ?



Thanks in advance

                                Daniel Tourde

--
*********************************************************************
Daniel TOURDE                                   E-mail : [hidden email]
The Aeronautical Research Institute of Sweden   Tel : +46 8 634 13 44
P.O. Box 11021 S-161 11 BROMMA, Sweden          Fax : +46 8  25 34 81
*********************************************************************


Reply | Threaded
Open this post in threaded view
|

Re: Use of fsolve

Mario Storti-5

>>>>> On Thu, 01 Oct 1998 18:08:46 +0200,
>>>>>      Daniel Tourde <[hidden email]> said:

> Hello,
> I would like to use the fsolve solution for solving non-linear equations
> where sometimes, solutions or constant are very small:

>   y(1) = 12*((x(3)*x(1))/2)/E - nlcoef(3);
>   y(2) = 12*((x(3)*x(2)+x(1)*x(4))/6)/E - nlcoef(4);
>   y(3) = 12*((P*x(3)/2+x(4)*x(2)+x(1)*x(5))/12)/E - nlcoef(5);
>   y(4) = 12*((P*x(4)/2+x(5)*x(2))/20)/E - nlcoef(6);
>   y(5) = 12*((P*x(5))/60)/E - nlcoef(7);

> Where some of my nlcoef values are very small (between 1e-7 and 1e-10).
> It happens that the solutions given by fsolve can be wrong due to
> rounding and precision errors.

> ................. < lines snipped here > ..............


Hi,

Perhaps you can get better values by rescaling the problem. If lambda is
a typical value for sqrt(nlcoef(k)*E), then solving the rescaled
system

> yy(1) = 12*((xx(3)*xx(1))/2) - nlcoef(3)*E/lambda^2;
> yy(2) = 12*((xx(3)*xx(2)+xx(1)*xx(4))/6) - nlcoef(4)*E/lambda^2;
> yy(3) = 12*((PP*xx(3)/2+xx(4)*xx(2)+xx(1)*xx(5))/12) - nlcoef(5)*E/lambda^2;
> yy(4) = 12*((PP*xx(4)/2+xx(5)*xx(2))/20) - nlcoef(6)*E/lambda^2;
> yy(5) = 12*((PP*xx(5))/60) - nlcoef(7)*E/lambda^2;

with PP=P/lambda perhaps is better scaled, since the
nlcoef(k)/lambda^2 are closer to one. After, you can recover the x
values from

octave> x=xx*lambda;

Are E and P also small?

Hope this helps,

Mario

--
========================================
Mario Storti
Centro Internacional de Metodos Computacionales en Ingenieria
INTEC (CONICET-UNL)
Guemes 3450, 3000 Santa Fe
Argentina
Tel: +54 42 55.91.75
Fax: +54 42 55.09.44
www: http://venus.unl.edu.ar/gtm-eng.html
e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Use of fsolve

John W. Eaton-6
In reply to this post by Daniel Tourde-3
On  1-Oct-1998, Daniel Tourde <[hidden email]> wrote:

| Then my question is the following: How can I change the iteration limit
| within fsolve.

There is currently no way to do that without changing the source.  To
gain more control over fsolve you would need to modify the code in
liboctave/NLEqn.cc to use hybrj instead of hybrj1 (see the
corresponding .f files in the libcruft/minpack directory).  Once the
C++ code in liboctave has been modified to allow control over the
iteration limit, it should be easy to modify fsolve.

| How can I improve the precision of Octave in its
| globality ? In a word, what is the best way to get rid of flag 4 and
| flag 3 ?

I've never been too impressed with Minpack's ability to solve sets of
nonlinear equations reliably.  Does anyone know of something better
that is also freely redistributable?

Thanks,

jwe


Reply | Threaded
Open this post in threaded view
|

Re: Use of fsolve

Daniel Tourde-3
In reply to this post by Mario Storti-5
Hello Mario,

> > I would like to use the fsolve solution for solving non-linear equations
> > where sometimes, solutions or constant are very small:
>
> >   y(1) = 12*((x(3)*x(1))/2)/E - nlcoef(3);
> >   y(2) = 12*((x(3)*x(2)+x(1)*x(4))/6)/E - nlcoef(4);
> >   y(3) = 12*((P*x(3)/2+x(4)*x(2)+x(1)*x(5))/12)/E - nlcoef(5);
> >   y(4) = 12*((P*x(4)/2+x(5)*x(2))/20)/E - nlcoef(6);
> >   y(5) = 12*((P*x(5))/60)/E - nlcoef(7);
>
> > Where some of my nlcoef values are very small (between 1e-7 and 1e-10).
> > It happens that the solutions given by fsolve can be wrong due to
> > rounding and precision errors.

 
> Perhaps you can get better values by rescaling the problem.

Thanks for your answer. Yes it has answered my question and helped me to
solve my problem (at least I got answers with index 1).
 
> Are E and P also small?

No, around 1e5 for E and 50 for P

 
> Hope this helps,

It has. Thanks


                        Daniel
--
*********************************************************************
Daniel TOURDE                                   E-mail : [hidden email]
The Aeronautical Research Institute of Sweden   Tel : +46 8 634 13 44
P.O. Box 11021 S-161 11 BROMMA, Sweden          Fax : +46 8  25 34 81
*********************************************************************