Code covered by the BSD License  

Highlights from
cxroot - Complex root of complex function

4.0

4.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 4.01 KB File ID: #22661

cxroot - Complex root of complex function

by Miroslav Balda

 

12 Jan 2009

The function solves a problem of complex root of a complex user-defined function.

| Watch this File

File Information
Description

The function finds a complex root of a complex function FUN by solving a system of two nonlinear real equations
   real(FUN(x)) = 0;
   imag(FUN(x)) = 0;
of a complex variable x = complex(real(x), imag(x)) by calling the function LMFnlsq from MathWorks, File Exchange:
   http://www.mathworks.com/matlabcentral/fileexchange/17534
ie. as a least squares problem without any need of functions from the Optimization Toolbox.
 
Calls of the function:
   cxroot % to display help
   x = cxroot(FUN)
   x = cxroot(FUN,x0)
   x = cxroot(FUN,x0,options)
where
     FUN is a name or handle of the function the root of which is sought. It is either normal m-function,
          or a nested function. In the later case, constant parameters of the function may be transfered
          from the calling procedure without globals (see Example).
     x0 is an initial guess of the complex root,
     options is a cell array of optional name and value pairs of parameters, which control iterations in the function LMFnlsq (see its help). If no options is given, default ones are used.
     x is a complex root of the function FUN,
     ssq is a sum of squares of residuals (differences from zero),
     cnt is a number of evaluations of FUN and Jacobian matrix, negative if no convergence (see LMFnlsq)
 
Example on user written function
   function [w,ssq,cnt] = AireAiPrime(k,c1,w0,Options)
   % AIREAIPRIME Function for complex root search
   [w,ssq,cnt] = cxroot(@funw,w0,Options{:});
       function fw = funw(w) % nested function = function formula
           Z = i*w*(6i*k)^(-2/3);
           fw = airy(k,Z)-c1*exp(i*pi/6);
       end % fw
    end % AireAiPrime
The function finds a root (with ssq -> 0), which is close to initial guess. Sometimes it finishes iterations in points, which are not roots. Such a situation is recognized by a nonzero value of ssq.
Results of a run of the script Airekc1 with the strting point w0 = 5+5i, Options = {'Display',-2}, and parameters of the function
          k = 1.0000 =>
          c1 = 1.0000 =>
          Re w0 = 5.0000 =>
          Im w0 = 5.0000 =>
**************************************************************************
  itr nfJ SUM(r^2) x dx
**************************************************************************
   0 1 7.1377e-001 5.0000e+000 0.0000e+000
                   5.0000e+000 0.0000e+000
   2 3 8.8108e-002 6.2365e+000 1.2514e+000
                   6.4646e+000 -1.2406e+000
   4 5 4.9009e-007 6.7102e+000 -6.8413e-002
                   6.2243e+000 -2.0625e-002
   
   6 7 1.9376e-027 6.7097e+000 -2.0633e-007
                   6.2256e+000 4.6777e-007
w =
    6.7097 + 6.2256i % ROOT
ssq =
    1.9376e-027 % SUM OF SQUARES
cnt =
    6 % NUMBER OF ITERATIONS
 
It is obvious that w is a root, because of ssq, which dropped from .7 to almost zero.

MATLAB release MATLAB 7.3 (R2006b)
Other requirements Windows and function LMFnlsq from FEX (Id 17534) for function cxroot. Function inp (Id 9033) for testing script Airekc1.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
11 May 2010 Daniel Paschall

Thanks! Really needed this, couldn't find this functionality elsewhere!

07 Jun 2011 Liber-T

Hye, I think your function is not able to solve equations that contains besselh(0 or 1,1,kx).
I don't know if you have a solution for that case.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
complex root Miroslav Balda 12 Jan 2009 16:35:36
complex function Miroslav Balda 12 Jan 2009 16:35:36
iteration Miroslav Balda 12 Jan 2009 16:35:36

Contact us at files@mathworks.com