Is it possible to use the "fsolve" function in the Optimization Toolbox to solve complex equations?

A function of a complex variable "z" is called a complex function "f(z)". I have the following complex function:
f(z) = z^2 - z + 1
How do I determine the zeros of this complex function?

 Akzeptierte Antwort

For release R2016b and after: 
Generally, Optimization Toolbox solvers do not accept or handle objective functions or constraints with complex values. However, the least-squares solvers "lsqcurvefit", "lsqnonlin", and "lsqlin", and the "fsolve" solver can handle these objective functions with some restrictions as mentioned in the following documentation:
The problem statement can be solved as follows:
>> f = @(z)1 + z^2 - z; >> x0 = 1 + 1i/10; >> y = fsolve(f,x0)
For release R2016a and before:
The "fsolve" function cannot directly handle complex-valued functions or variables. However, a complex-valued function of a complex variable "z" can also be thought of as a system of 2 real-valued equations in 2 real variables.
Consider the problem statement:
f(z) = z^2 - z + 1
To solve this complex function using the "fsolve" function, we first create the following function file:
function F = myfun(X)     z = X(1, :) + j*X(2, :); % Create complex value from real and imaginary parts     f = z.^2 - z + 1; % Evaluate complex function     F = [real(f); imag(f)]; % Separate real and imaginary parts
Then, using the initial guess "z = 1 + 2j", the function can be solved by the following command:
>> [z fval] = fsolve(@myfun, [1; 2])
which produces the results:
z =     0.5000     0.8661 fval =   6.2523e-005
Therefore, the complex value that produces a local minimum of "abs(f(z))" is found to be:
z = 0.5 + i*0.8661

Weitere Antworten (0)

Kategorien

Produkte

Version

Noch keine Version eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by