Solve nonlinear complex equations

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!

 Réponse acceptée

Matt J
Matt J le 10 Fév 2013
Modifié(e) : Matt J le 10 Fév 2013

0 votes

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.

11 commentaires

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
Ed le 10 Fév 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
Matt J le 10 Fév 2013
Modifié(e) : Matt J le 10 Fév 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. "
Meng Li
Meng Li le 13 Juil 2015
Do you know how to solve two complex variables function such as f=cot(z1)*z2 -(1-z2^2*(1+i*z1))?
f=@(z1,z2)cot(z1)*z2 -(1-z2^2*(1+i*z1));
c=@(x) complex(x(1),x(2));
g=@(x) abs(f(c(x(1:2)),c(x(3:4))));
sol=c(fminsearch(g,[1;1;1;1]))
Meng Li
Meng Li le 18 Juil 2015
Modifié(e) : Matt J le 18 Juil 2015
Thank you so much! I have tried this code and it works.
f=@(z1,z2)cot(z1)*z2 -(1-z2^2*(1+i*z1));
c1=@(x) complex(x(1),x(2));
c2=@(x) complex(x(1),x(2));
g=@(x) abs(f(c(x(1:2)),c(x(3:4))));
sol_z1=c1(fminsearch(g,[1;1;1;1]))
sol_z2=c2(fminsearch(g,[1;1;1;1]))
However, when I change the the guess value from [1;1;1;1] to [1;1;1;2], the solutions will change!(from z1=0.41955 + 0.61006i, z2=0.75228 + 0.88927i to z1=0.72735 + 0.98611i, z2=1.581 - 0.4017i) I have put this roots into the equation and find that they satisfy the equation. Even though this small change make no difference for the equations, when I proceed the roots afterwards, it will produce big difference(for example take the imaginary part of z2, one is +, the other is -). How can I obtain the precise(unchanged) equations' roots when the guess values change? I'm so confused about this. This question is fairly long and I hopefully it doesn't take you too much time. Thank you anyway!
Walter Roberson
Walter Roberson le 18 Juil 2015
You have a function with multiple roots, something there are multiple solutions for. You want to always get the same solution out no matter how you change your initial conditions. In order for that to happen you would need to define some criteria that would mathematically favor one root over another. What are the properties of the root that you want that the other roots would not have? For example is the root that you want to have selected the only root that has a positive imaginary part?
Meng Li
Meng Li le 20 Juil 2015
Actually, my question is quite complex. I have attached the equation I'm trying to solve. Delta(eff),Delta(a),Delta(c) are 90 by 1 dimensional matrices, of which the components are complex numbers. a, c are real numbers. Delta(eff) is already known. I will use fminsearch function to obtain the possible roots Delta(a),Delta(c). I have written the Matlab code to solve it. But whenever I change the initial guess value for Delta(a), Delta(c), the output results of Delta(a),Delta(c) will change. I don't know whether I should put some criteria to choose some particular values and what kind of constrains I should use. Is there any function can solve this kind of problem? Is Mathematica good at solving it or it's same with Matlab? Thank you so much!
Meng Li
Meng Li le 20 Juil 2015
Modifié(e) : Walter Roberson le 21 Juil 2015
It seems there is no uploaded file. I will write down the equations.
Delta(eff)=4ac*Sum(1/n^2*tanh(alpha_n)/alpha_n+tanh(beta_n)/beta_n) (n is odd integer, it starts from 1 to infinity);
where
alpha_n=c/(2*Delta(a))*sqrt(1+(n*pi*Delta(c)/a)^2);
beta_n=a/(2*Delta(c))*sqrt(1+(n*pi*Delta(a)/c)^2);
Walter Roberson
Walter Roberson le 21 Juil 2015
You should start a new Question on this.
eff does not appear on the right hand side of your question so I do not know what the (eff) on the left relates to.
You define alpha_n and beta_n in terms of Delta(a) and Delta(c) but there is no obvious way of calculating either of those.
In your Delta(eff) formula, is 4ac = 4*a*c ?
Is alpha_n indicating alpha indexed at n?
Is the sum over odd n from 1 to infinity?
If Delta is being defined recursively (because it is defined in terms of alpha_n and beta_n that are defined in terms of Delta) then you need an initial condition.
Meng Li
Meng Li le 21 Juil 2015
Delta(eff) is a experimentally measured value and this value can be separated into Delta(a) and Delta(c) through the first equation.
Yes. 4ac=4*a*c; Yes. alpha_n indicating alpha at n; Yes. the sum is over integer from 1 to infinity;
If I want to solve the equation, I should give some initial guess value for Delta(a) and Delta(c). Because the function 'fminsearch' can only give local solutions, I think the initial guess will be very important.

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 10 Fév 2013

0 votes

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 commentaires

Matt J
Matt J le 10 Fév 2013
Modifié(e) : Matt J le 10 Fév 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
Ed le 10 Fév 2013
I tried the fsolve but unfortunately it seems to be related just to real functions. Thanks!

Connectez-vous pour commenter.

Question posée :

Ed
le 10 Fév 2013

Commenté :

le 21 Juil 2015

Community Treasure Hunt

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

Start Hunting!

Translated by