Matlab function
Show older comments
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
More Answers (2)
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
on 20 Jun 2011
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
on 20 Jun 2011
Liber-T's function is not separable: it involves complex integrals.
Liber-T
on 20 Jun 2011
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
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
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
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".)
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!