Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solve nonlinear complex equations

Asked by Ed on 10 Feb 2013

Hello,

I am trying to numerically solve a nonlinear complex equation and I would like to find all the complex roots. The equation is of the type:

cot(z)*z = 1-z^2*(1+i*z)

Does a specific function exist to find all the complex roots or do I need to separate z in the real and imaginary parts?

Thanks in advance for your help!

0 Comments

Ed

Products

No products are associated with this question.

2 Answers

Answer by Matt J on 10 Feb 2013
Edited by Matt J on 10 Feb 2013
Accepted answer

If you have the Symbolic Math Toolbox, I think SOLVE can be used to get complex-valued solutions. For the numerical solvers, I'm pretty sure you do have to reformulate the problem in terms of real and complex parts. Also, I've never heard of a numerical solver that will robustly find multiple roots for anything except polynomials.

3 Comments

Matt J on 10 Feb 2013

However, you don't have to explicitly/analytically rewrite your equation to pose it in terms of real and complex parts. Here's what you can do instead,

   f=@(z)cot(z)*z -(1-z^2*(1+i*z));
   c=@(x) complex(x(1),x(2));
   g=@(x) abs(f(c(x)));
>> sol=c(fminsearch(g,[1;1]))   %one root
sol =
    -1.0900e-05 - 3.4270e-05i
Ed on 10 Feb 2013

Thanks for answering, I used your code and everything is fine, but I still have a question (sorry!):

the root that you find with the second method is just one. What should I do to find the others? Do I have to change the interval of the search? If so, this method should be much easier than to pose the equation in terms of real and complex parts!

Thanks again!

Matt J on 10 Feb 2013

FMINSEARCH doesn't give you control over the interval of the search. It just let's you choose a starting point hopefully close to the thing you're trying to find. If you know the approximate locations of the other roots, you could try initializing at them. Beyond that, see my earlier remark " I've never heard of a numerical solver that will robustly find multiple roots for anything except polynomials. "

Matt J
Answer by Azzi Abdelmalek on 10 Feb 2013

Use fzero function

doc fzero
f=@(z)cot(z)*z -(1-z^2*(1+i*z))
z0=i;
sol=fzero(f,z0);  % the solution is near z0

2 Comments

Matt J on 10 Feb 2013

It's interesting that this worked for z0=i, but it appears to be just a fluke. FZERO can't really handle complex-valued functions. Note,

>> sol=fzero(f,1+i)
Error using fzero (line 309)
Function value at starting guess must be finite and real.
Ed on 10 Feb 2013

I tried the fsolve but unfortunately it seems to be related just to real functions. Thanks!

Azzi Abdelmalek

Contact us