Fzero for functions that are never negative?

 Classic List Threaded
6 messages
Reply | Threaded
Open this post in threaded view
|

Fzero for functions that are never negative?

 I felt this was important enough to give it its own thread... Using fzero, 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? In a particular problem I am dealing with, I must find the root of f(x) = abs(x-9.1)^4.5 using fzero, and I am supplied with initial x values of 8.0 and 13.0. But fzero fails if I pass these values as an initial bracket, and passing only one of them fails also. Is it impossible to solve such functions using fzero?
Reply | Threaded
Open this post in threaded view
|

Re: Fzero for functions that are never negative?

 On 18 October 2012 14:20, Joza <[hidden email]> wrote: > Using fzero, 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) One doesn't; one uses fsolve instead. - 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 for functions that are never negative?

 In reply to this post by Joza Am 18.10.2012 20:20, schrieb Joza: > But fzero fails if I pass these values as an initial bracket, and passing > only one of them fails also. Is it impossible to solve such functions using > fzero? Same answer as in the other thread: Use fsolve instead of fzero. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Fzero for functions that are never negative?

 In reply to this post by Joza On Thu, Oct 18, 2012 at 2:20 PM, Joza wrote: I felt this was important enough to give it its own thread... Using fzero, 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? In a particular problem I am dealing with, I must find the root of f(x) = abs(x-9.1)^4.5 using fzero, and I am supplied with initial x values of 8.0 and 13.0. But fzero fails if I pass these values as an initial bracket, and passing only one of them fails also. Is it impossible to solve such functions using fzero? -- View this message in context: http://octave.1599824.n4.nabble.com/Fzero-for-functions-that-are-never-negative-tp4645439.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 Through away the ABS find the zeroes state the the zeroes are the same.-- DAShttps://linuxcounter.net/user/206392.html _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Fzero for functions that are never negative?

 In reply to this post by Joza Thanks for all the input guys, I've been thinking about it all!!! :-) As regards the fsolve function, is it possible to specify the x-convergence test for EACH ITERATION? I know can input the absolute convergence error for "TolX", but I would rather test each iteration, which will depend on the value obtained in the previous iteration. Is that possible? I'm also curious, does it happen often that simple self-made algorithms can provide better answers than Octave's built-in functions?
Reply | Threaded
Open this post in threaded view
|

Re: Fzero for functions that are never negative?

 On 10/18/2012 05:16 PM, Joza wrote: > As regards the fsolve function, is it possible to specify the x-convergence > test for EACH ITERATION? I know can input the absolute convergence error for > "TolX", but I would rather test each iteration, which will depend on the > value obtained in the previous iteration. Is that possible? You can very simply modify almost all(*) Octave built-in functions, because they are often implemented in Octave/Matlab language. If you 'type fzero', you'll see the implementation of the function 'fzero'; you can edit it to do what you want and redefine fzero() or create my_fzero(). > > I'm also curious, does it happen often that simple self-made algorithms can > provide better answers than Octave's built-in functions? For a specific case, yes, of course---the Octave built-ins are by design handling a general case, so if you can figure out a shortcut that works better for your specific case, it'll beat the built-in. I don't know whether it 'happens often', but new algorithms do appear even though a lot of smart people worked for a long time to implement Octave's built-ins. If you can think of a self-made algorithm that's better than the current one, please contribute it---that's the beauty of Free Software. (*) some Octave functions are implemented in C/C++/Fortran; it's possible to modify them as well but it's a little more involved. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave