cxroot - Complex root of complex function

The function solves a problem of complex root of a complex user-defined function.
2,8K Downloads
Aktualisiert 12. Jan 2009

Lizenz anzeigen

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.

Zitieren als

Miroslav Balda (2026). cxroot - Complex root of complex function (https://de.mathworks.com/matlabcentral/fileexchange/22661-cxroot-complex-root-of-complex-function), MATLAB Central File Exchange. Abgerufen.

Kompatibilität der MATLAB-Version
Erstellt mit R2006b
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS Linux
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und MATLAB Answers
Version Veröffentlicht Versionshinweise
1.0.0.0