5.0

5.0 | 4 ratings Rate this file 11 Downloads (last 30 days) File Size: 2.92 KB File ID: #19050

Muller

by Daniel Cortes

 

04 Mar 2008 (Updated 06 Mar 2008)

Find a zero crossing of a real or complex function using Muller's method

| Watch this File

File Information
Description

This function find the zero of a real or complex (analytic) function using the Muller's method. The user must provide three initial guesses close the desired zero. The user can set the maximun number of iterations and other convergence parameters.

The outputs of the function are the value of the variable corresponding to the zero, the value of the function and the number of iterations used.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
05 Mar 2008 John D'Errico

I had some hopes for this submission. Its got a few flaws though.

The interface is a bit kludgy. If you need three points to start up the function, then why not input a vector of length three? Forcing the user to input three separate scalar arguments is silly here.

Good code will tell the user whether these points must bracket the root, or if that matters not. It will even have a reference for Muller's method, perhaps a URL that a user might loop up. Good code will verify that the points supplied were distinct. None of that was found in this code.

More importantly, the function MUST be a character string. Function handles, inline functions, etc., need not apply. Note that the help does not state this as a requirement. You will need to find that out for yourself. So then I tried a string. Nope, it fails too.

[res,fval,it] = muller('(x-1).^3',2,3,4)
??? Invalid function name '(x-1).^3'.

Error in ==> muller at 129
y0 = feval ( f, z0);

Should the function be vectorized? We don't know, since the help is not that helpful.

Other problems? When you write code that has default for some parameters (note that defaults are good things in general) you need to tell the user what those defaults will be!!! The help never states what the default maximum number of iterations is, or the default tolerances. Again, the user is left to guess.

Finally, I'd suggest an example would be useful for most users.

My rating here was in the range 2-3, but the irritation factor of not being able to use this with any function that was not an m-file name pushed me down to a 2. I'll suggest that most users will want to just formulate an anonymous function to use. That will fail here. Its silly, since the author specified release 14. So anybody who uses this code can use an anonymous function.

05 Mar 2008 Daniel Cortes

The file has been modified according to the review of John D'Errico.

Daniel H. Cortes

06 Mar 2008 John D'Errico

My thanks for cleaning up this tool. Its now a useful alternative to something like fzero. Note that if no real root exists, this will find a complex one. For example,

x = muller(@(x) x^2+1,[1 2 3])
x =
            0 + 1i

This ability to look in the complex plane will be useful to some. Of course, its always important to be careful with any numerical tool. Understand the properties of your tools. For example, this next function clearly has a real root at x == 4. But higher order roots are difficult to resolve, so the default tolerance misses the root by a bit.

x = muller(@(x) (x-4).^3,[1 2 3])
x =
       4.0131 + 0.013627i

If we now crank the tolerance down fairly small, we see a better result.

x = muller(@(x) (x-4).^3,[1 2 3],[],eps,eps,'both')
x =
            4 - 4.7346e-16i

So a user should always understand how their tools will behave.

07 Mar 2008 John D'Errico

Let me expand on my comments. The ability of muller to work in the complex domain is both a blessing and a curse. If your function has complex root, this code will find it nicely, whereas fzero should fail. But if you absolutely need to stay on the real line, then beware, as muller will happily try to test your function away from the real line.

So muller deserves its place as an alternative to fzero. But I'll repeat - always know your problem. Understand your objectives and the abilities of the tools you will use.

19 Aug 2008 Alec alectf@udel.edu

Great tool. Thanks!

28 Dec 2008 liuxbin xbin  
Please login to add a comment or rating.
Updates
05 Mar 2008

Corrections made according to the review of John D'Errico.

06 Mar 2008

Corrections made according to the review of John D'Errico.

Tag Activity for this File
Tag Applied By Date/Time
approximation Daniel Cortes 22 Oct 2008 09:51:53
interpolation Daniel Cortes 22 Oct 2008 09:51:53
muller Daniel Cortes 22 Oct 2008 09:51:53
zero crossing of a function Daniel Cortes 22 Oct 2008 09:51:53
complex function Daniel Cortes 22 Oct 2008 09:51:53

Contact us at files@mathworks.com