Matlab function

I need to solve a problem, here are my need:
-To find the zeros of a function
-The function is complex
-The zeros are complex
-The function is nonlinear
-I know the approximate place of the zero I'm searching
-I need to bound the search of the zero.
The function I've tried and does not work:
-fsolve (I can't bound the search and sometimes doesn't give me what I want)
-fzero(doesn't work at all)
-solve(doesn't work at all)
Just write the function I could use to find zeros please.

 Accepted Answer

Walter Roberson
Walter Roberson on 20 Jun 2011

1 vote

Supply it with a vector of length 2, and internally construct x = xin(1) + 1i*xin(2), and calculate the complex result. Output the vector of length 2 which is real() and imag() of that result. The constraints you would supply would be the bounds on the real and imaginary parts (expressed as real numbers.)

4 Comments

Walter Roberson
Walter Roberson on 21 Jun 2011
Thinking again you probably want to output something like the magnitude of the complex result, since fmincon is a minimizer instead of a zero finder.
Liber-T
Liber-T on 21 Jun 2011
I used abs on my function.
But finally there is still a problem with fmincon, since it is much slower than fsolve and still innacurate. It has find the way to give me answer out of bound.
Matt Fig
Matt Fig on 21 Jun 2011
I see your post of the function in another question, but you haven't told us many of the variables in that function. Why not post the COMPLETE function, with all variables defined, so that we can copy and paste it into MATLAB and it will work? For example, your function has a variable 'y' and a variable 'ne0' in it, which you have not defined. Is e equal to the exp(1)?
Liber-T
Liber-T on 22 Jun 2011
http://www.mathworks.com/matlabcentral/answers/9756-solve-det-and-ode-faster
I've posted everything here.

Sign in to comment.

More Answers (2)

the cyclist
the cyclist on 20 Jun 2011
For a complex zero, both the real and imaginary parts must be zero, and you can take advantage of this.
I believe you can use fzero() to do this, by separately solving for the real and imaginary zeros. For example, suppose your function is f(x) = x - i. Then,
fr = @(x) real(x - i)
fi = @(x) imag(x - i)
x0r = fzero(fr,3)
x0i = fzero(fi,3i)
You don't specify the bounds, but you do have the initial guess to get close to the zero. (Here, I just arbitrarily set my initial guess to "3" for both the real and imaginary parts.)
I hope this helps.

8 Comments

Liber-T
Liber-T on 20 Jun 2011
This is a really good idea but, I already tried to separate the function with real and imag, but fzero still didn't work as solve.
the cyclist
the cyclist on 20 Jun 2011
Maybe you could post some code? As you can see from my simple example, the method can work in some cases.
Walter Roberson
Walter Roberson on 20 Jun 2011
Liber-T's function is not separable: it involves complex integrals.
Liber-T
Liber-T on 20 Jun 2011
I have post my function at other place, but here I just want to know every possible thing I could use, everything known.
the cyclist
the cyclist on 21 Jun 2011
Walter, I'm curious why the function needs to be separable (assuming you mean analytically so). Since it's all presumably numerical in the end, why wouldn't my method work?
Walter Roberson
Walter Roberson on 21 Jun 2011
The function involves terms that are work differently for complex arguments -- e.g., branch cuts, path of integration becomes important for complex integrals, complex number to a power might end up at a very different angle on the plane than if one considered the real and imaginary parts separately.
Besides, finding an xr at which real(f(xr)) is 0, and an xi at which imag(f(xi)) is 0, is very different than saying f(xr+i*xi) will be 0 + 0i .
the cyclist
the cyclist on 21 Jun 2011
Your last statement is true, but it is not what I meant to propose. I did not mean:
real(f(xr))=0 and imag(f(xi))=0,
but rather
real(f(x)) = 0 and imag(f(x))=0.
Note the different arguments. These two statement, taken together, are equivalent to your f(xr+i*xi)=0+0i.
However, I think you are absolutely correct that my proposed solution will not work with the function as you describe it. But will any MATLAB function really handle all the branch cuts, etc, well?
Walter Roberson
Walter Roberson on 22 Jun 2011
I do not know how well MATLAB functions handle branch cuts.
Your sample algorithm solves for real(f(xr))=0 and imag(f(xi))=0. If there are multiple zeros on either the real or imaginary axis (as is likely) then finding the place the zeros coincide would require looping with careful manipulation of the intervals... and some work to generate new intervals as the signs of the function must be different at the two interval endpoints for fzero (it isn't as easy as saying "search 0 to 1; now search 1 to 2".)

Sign in to comment.

Matt Fig
Matt Fig on 20 Jun 2011

1 vote

If you have an explicit function of one variable, you might have luck with a Newton's method root finder.

Categories

Find more on Function Creation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!