Filter löschen
Filter löschen

Solving 8-equations system in 8 variables with lsqnonlin()

3 Ansichten (letzte 30 Tage)
Hi I'm trying to use lsqnonlin with this system:
'file.m' if true % code
function y = prova_in_s(x,Sm,S_std,g_m,g_l)
T1=tras_scatter_par(Sm(:,1:2)); T_std1=tras_scatter_par(S_std(:,1:2)); S_probe=[x(1)+i*x(5),x(2)+i*x(6);x(3)+i*x(7),x(4)+i*x(8)]; T_probe=tras_scatter_par(S_probe);
parz=[real(T_probe*T_std1*T_probe-T1); imag(T_probe*T_std1*T_probe-T1)];
if numel(Sm)>4 T2=tras_scatter_par(Sm(:,3:4)); T_std2=tras_scatter_par(S_std(:,3:4));
parz2=[real(T_probe*T_std2*T_probe-T2); imag(T_probe*T_std2*T_probe-T2)];
% parz2=[real(T_probe*T_std2); % imag(T_probe*T_std2)]; %
end
for cicles=1:numel(g_m) loadst(cicles)=(g_l(cicles)*(T_probe(1,2))/(T_probe(1,1))+1)*g_m(cicles)-g_l(cicles)*det(T_probe)*(T_probe(2,2))/(T_probe(1,1))-((T_probe(2,1))/(T_probe(1,1))); end
for cicles=1:numel(g_m) if cicles==1 parz_load=[real(loadst(cicles));imag(loadst(cicles))]; else parz_load=[parz_load;real(loadst(cicles));imag(loadst(cicles))]; end end
y1=[parz(1);parz(2);parz(3);parz(4);parz(5);parz(6);parz(7);parz(8);parz_load];
y2=[parz(1);parz(2);parz(3);parz(4);parz(5);parz(6);parz(7);parz(8)];
if numel(Sm)>4 y=[y1;y2]; else y=y1;
end end
The problem consists in:
varyng the coefficients of the equations the solver calculate a wrong solution with an error of 20-30 % from the real solution. I thought that a reason is that the solution is not unique...so the choose of the intial guess, x0, is fundamental...i could adjust the FunTol too..anyway i call lsqnonlin in this form: " [x_sol,resnorm] = lsqnonlin(@(x)prova_in_s(x,a,b,c,gamma_std),x0,lbo,ubo); " how can i adjust FunTol? if I try to pass the option structure it return me an error. I read also thet optimset is not valid for lsqnonlin, so how i can adjust the options like algorithm etc.. Thank you in advance for your help.

Akzeptierte Antwort

Shashank Prasanna
Shashank Prasanna am 25 Jan. 2013
optimset indeed is supported by LSQNONLIN. Just make sure its the 5th argument. Not all options are available for all solvers, but here is reference that can help:
From your objective function it seems like it is combinatorial in nature. I am not sure LSQNOLIN is perfectly suited for this type of problems, which is more suited for least squares (min sum of squares) kind of problems. Which are always smooth. But with jumps and discontinuities, I would rather go with a global optim approach such as GA which is stochastic and can handle such behavior.
  2 Kommentare
Daniele
Daniele am 25 Jan. 2013
Bearbeitet: Daniele am 25 Jan. 2013
i can also pute the system in this form:
v1*(v2 + 10*v5 + 2*v6) - v3*(v1 + (2*v2)/5 + 2*v5 + (2*v6)/5) - v7*(2*v1 + (2*v2)/5 - v5 - (2*v6)/5) + v5*(10*v1 + 2*v2 - v6) - 4
v1*(v4 + 10*v7 + 2*v8) - v3*(v3 + (2*v4)/5 + 2*v7 + (2*v8)/5) - v7*(2*v3 + (2*v4)/5 - v7 - (2*v8)/5) + v5*(10*v3 + 2*v4 - v8) - 1
v5*(v2 + 10*v5 + 2*v6) - v7*(v1 + (2*v2)/5 + 2*v5 + (2*v6)/5) + v3*(2*v1 + (2*v2)/5 - v5 - (2*v6)/5) - v1*(10*v1 + 2*v2 - v6) + 2
v5*(v4 + 10*v7 + 2*v8) - v7*(v3 + (2*v4)/5 + 2*v7 + (2*v8)/5) + v3*(2*v3 + (2*v4)/5 - v7 - (2*v8)/5) - v1*(10*v3 + 2*v4 - v8) + 1/2
v2*(v2 + 10*v5 + 2*v6) - v4*(v1 + (2*v2)/5 + 2*v5 + (2*v6)/5) - v8*(2*v1 + (2*v2)/5 - v5 - (2*v6)/5) + v6*(10*v1 + 2*v2 - v6) + 1
v2*(v4 + 10*v7 + 2*v8) - v4*(v3 + (2*v4)/5 + 2*v7 + (2*v8)/5) - v8*(2*v3 + (2*v4)/5 - v7 - (2*v8)/5) + v6*(10*v3 + 2*v4 - v8) + 1/20
v6*(v2 + 10*v5 + 2*v6) - v8*(v1 + (2*v2)/5 + 2*v5 + (2*v6)/5) + v4*(2*v1 + (2*v2)/5 - v5 - (2*v6)/5) - v2*(10*v1 + 2*v2 - v6) - 1/2
v6*(v4 + 10*v7 + 2*v8) - v8*(v3 + (2*v4)/5 + 2*v7 + (2*v8)/5) + v4*(2*v3 + (2*v4)/5 - v7 - (2*v8)/5) - v2*(10*v3 + 2*v4 - v8) - 9/40
that are polynomials, so without discontinuities, but the problem is the same. (v1...v8 are my variables). it looks strange that lsqnonlin doesn't manage to resolve polynomials.. anyway i'll try GA. thank you for your answer!
Shashank Prasanna
Shashank Prasanna am 25 Jan. 2013
The above looks solvable, did optimset work for you? Just replace v1...v8 by x(1)...x(8) and pass it to lsqnonlin, i'd also recommend FMINCON since this is not exactly a least squares problem. Both are gradient based and will not work if you have discontinuities.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Manual Performance Optimization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by