Solving 8-equations system in 8 variables with lsqnonlin()
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
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
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.
Weitere Antworten (0)
Siehe auch
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!