Fsolve for complexe adding variable
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello everybody
I tried to solve an equation , which solution is a complexe.
clc
[z, fval] = fsolve(@myfun, [1; 1] )
function F = myfun(X)
z = X(1, :) + i*X(2, :); % Create complex value from real and imaginary parts
A=4*(z) ./ ((z)).^2;
B= exp(-i.*(z).*2.128958086786507e+04.*1.300000000000000e-06);
C= ( ((z)-1)./((z)+1) ).^2;
f = A.*B./(1+C) - 0.180699042773709 + 0.075060653715432i; % Evaluate complex function
F = [real(f); imag(f)]; % Separate real and imaginary parts
end
I's working, but in B, the 2 last value are vector, B= exp(-i.*(z).* k.* R); so I need to solve it for each value of k and R.
But if I write
B= exp(-i.*(z).* k1.*1.300000000000000e-06); % k1=k(1)
Unrecognized function or variable 'k1'.
Error in test>myfun (line 15)
B= exp(-i.*(z).*k1.*1.300000000000000e-06);
Error in fsolve (line 258)
fuser = feval(funfcn{3},x,varargin{:});
Error in test (line 8)
[z, fval] = fsolve(@myfun, [1; 1] );
Caused by:
Failure in initial objective function evaluation.
FSOLVE cannot continue.
Don't understand how I can solve it
Thank you in advance.
M
0 commentaires
Réponses (2)
Tarunbir Gambhir
le 30 Oct 2020
The function "fsolve" is a Nonlinear system solver which solves a problem specified by F(x) = 0 for x, where F(x) is a function that returns a vector value. In your first code, the function solved for the vector "X" successfully.
After making the change you get an error for unrecognized function or variable "k1" because you have not declared the variable anywhere in the function body.
If you want to solve the system for different parameters "k" and "R", I suggest you use an anonymous function with "fsolve" to get solution of the system for each set of parameters.
0 commentaires
Voir également
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!