lsqnonlin for 2 independent variables

12 次查看(过去 30 天)
I want to find 2 variables(x,y -> complex number) with lsqnonlin function.
For example, I have 2 equations and 2 variable DATA.
Please check and advise my code. Thank you~
<DATA>
S11=1+i;
S21=2+2i;
<EQUATION>
1) S11=x*y+i*(x+y)
2) S21=x*y-i*(x^2+y^2)
---------------------
clear all;
clc;
close all;
S11=1+i;
S21=2+2i;
x0=0.1+0.1i;
y0=0.2+0.2i;
F = @(x) myfun_lsq(x,y,S11,S21)
x=lsqnonlin(F,x0)
y=lsqnonlin(F,y0)
function F = myfun_lsq(x,y,S11,S21)
Fc1=x*y+i*(x*y)-S11;
Fc2=x*y-i*(x^2+y^2)-S21;
F = [Fc1, Fc2];
end

采纳的回答

Rik
Rik 2021-8-29
You should merge x and y to a single variable (i.e. a 2 element vector). That way you can do this with a single call to lsqnonlin.
And you should remove that clc, clear all, close all. You don't need it and using it is a clear indication you don't know what you want to happen. Are you opening any figures? Do you really want to reduce the performance of several functions by wiping the optimization from memory with clear all?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by