

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?


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.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


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(x9.1)^4.5;
X1 = 8.0
X2 = 13.0


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(x9.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. .
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


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?


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 ?
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


Not necessarily easy, although it was somewhat fun actually using all the code knowledge. This wasn't the only task mind you!


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?


On Thu, Oct 18, 2012 at 1:46 PM, Joza <[hidden email]> wrote: Since fzero depends on a change of sign, then I'd probably say for a function that is nonnegative, 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
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave


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(x9.1)^4.5, 8, optimset("TolFun", 1e20))
ans = 9.0999
_______________________________________________
Helpoctave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/helpoctave

