fzero tolerance issue ... and a related bug

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

fzero tolerance issue ... and a related bug

Joza
Hi guys.

So I would like to use fzero to solve for the root of a function. The tolerance test I would like to use however is a bit tricky:

I would like to refer to the value of each iteration of the fzero function, and stop when the difference between two values from two consecutive iterations is less that a particular value. But how do I refer to the output from each iteration of fzero? And baring in mind, I have a starting interval [x1, x2] for the function also. My test refers to machine_epsilon times the absolute value from that iteration.

As an aside, when I run the function with default tolerance, I get a message that a valid initial bracket cannot be constructed ... but I am SUPPLYING the initial bracket!!!? Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Jordi Gutiérrez Hermoso-2
On 17 October 2012 15:26, Joza <[hidden email]> wrote:
> As an aside, when I run the function with default tolerance, I get a message
> that a valid initial bracket cannot be constructed ... but I am SUPPLYING
> the initial bracket!!!? Any ideas?

Is the initial bracket valid? Can you please post the code that is
producing this?

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Joza
function [zero iterations] = Mzero(X1, X2, Xtol, Max_its)

[X, fval, INFO, OUTPUT ] = fzero( "FUN", [X1,X2], optimset("MaxIter", Max_its ) );

zero = X;
iterations = OUTPUT.iterations;
**************************************************************************************************************
"FUN" = abs(x-9.1)^4.5;

X1 = 8.0
X2 = 13.0
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Jordi Gutiérrez Hermoso-2
On 17 October 2012 15:52, Joza <[hidden email]> wrote:

> function [zero iterations] = Mzero(X1, X2, Xtol, Max_its)
>
> [X, fval, INFO, OUTPUT ] = fzero( "FUN", [X1,X2], optimset("MaxIter",
> Max_its ) );
>
> zero = X;
> iterations = OUTPUT.iterations;
> **************************************************************************************************************
> "FUN" = abs(x-9.1)^4.5;
>
> X1 = 8.0
> X2 = 13.0

FUN is always nonnegative, so there is no valid bracketing except the
trivial bracketing [9.1, 9,1].  A valid bracketing [x1, x2] in such
that x1*x2 <= 0.

You should use a method based on minimisation instead of one based on
bracketing.

- Jordi G. .
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Joza
Thank you for the insight!!

This is a problem that was given to me by my lecturer. I was simply asked to write a code that calls Matlab's own zero finding function, and use it to solve the problem. So it seems there is a problem with the function that HE has given me?
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

marco atzeri-2
On 10/18/2012 11:24 AM, Joza wrote:
> Thank you for the insight!!
>
> This is a problem that was given to me by my lecturer. I was simply asked to
> write a code that calls Matlab's own zero finding function, and use it to
> solve the problem. So it seems there is a problem with the function that HE
> has given me?
>

too easy otherwise ?


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Joza
Not necessarily easy, although it was somewhat fun actually using all the code knowledge. This wasn't the only task mind you!
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

Joza
So related to all that above, how does one find the root of a function that is always positive, or zero, but never negative? For instance, an absolute value:  f(x) = abs(x - 2)

This has root 2, but I can't give it an initial bracket [x1,x2] since f(x2)*f(x2) >= 0.
Indeed, how could fzero even find an initial bracket?

So how can one solve such a simple equation with fzero?
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

James Sherman Jr.-2
On Thu, Oct 18, 2012 at 1:46 PM, Joza <[hidden email]> wrote:
So related to all that above, how does one find the root of a function that
is always positive, or zero, but never negative? For instance, an absolute
value:  f(x) = abs(x - 2)

This has root 2, but I can't give it an initial bracket [x1,x2] since
f(x2)*f(x2) >= 0.
Indeed, how could fzero even find an initial bracket?

So how can one solve such a simple equation with fzero?



--
View this message in context: http://octave.1599824.n4.nabble.com/fzero-tolerance-issue-and-a-related-bug-tp4645391p4645433.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave

Since fzero depends on a change of sign, then I'd probably say for a function that is non-negative, you'd have to do some kind of preprocessing on that function.  You could try feeding the derivative of a function into fzero, thereby finding the local extrema, then checking whether the extrema are zeros.  In general, I believe finding zeros of those types of functions is better served using a gradient descent solution.

Hope this helps,

James Sherman


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

martin_helm
In reply to this post by Joza
Am 18.10.2012 19:46, schrieb Joza:

> So related to all that above, how does one find the root of a function that
> is always positive, or zero, but never negative? For instance, an absolute
> value:  f(x) = abs(x - 2)
>
> This has root 2, but I can't give it an initial bracket [x1,x2] since
> f(x2)*f(x2) >= 0.
> Indeed, how could fzero even find an initial bracket?
>
> So how can one solve such a simple equation with fzero?
>
You simply do not solve such an equation with fzero since it does not
belong to the class of equations fzero is made for, instead use fsolve
fsolve( @(x) abs(x-9.1)^4.5, 8, optimset("TolFun", 1e-20))
ans =  9.0999

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: fzero tolerance issue ... and a related bug

marco atzeri-2
In reply to this post by Joza
On 10/18/2012 7:46 PM, Joza wrote:
> So related to all that above, how does one find the root of a function that
> is always positive, or zero, but never negative? For instance, an absolute
> value:  f(x) = abs(x - 2)

look for the minimum
http://www.gnu.org/software/octave/doc/interpreter/Minimizers.html#Minimizers

>
> This has root 2, but I can't give it an initial bracket [x1,x2] since
> f(x2)*f(x2) >= 0.
> Indeed, how could fzero even find an initial bracket?
>
> So how can one solve such a simple equation with fzero?
>



_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave