Convergence problem for several variables

7 vues (au cours des 30 derniers jours)
Magnus
Magnus le 21 Oct 2014
Commenté : Magnus le 24 Oct 2014
Dear all,
I attempt to solve a convergence problem for nine variables that are subject to optimisation and nine equations. Each equation depends on at least 3 other variables that need to be optimised My idea is to use nine nested while loops. As the problem covers some space, the following is a simplified example which, hopefully, clearifies the issue. (Explanation see below)
clc
clear ap ap_plus aopt counta bp bp_plus bopt countb
clear coll_counta coll_countb counta_coll countb_coll
ap=1; %lower boundary, value a
ap_plus=100; %upper boundary, value a
aopt=0.1; %starting value
counta=0; % count iteration steps for value a
bp=1; %lower boundary, value b
bp_plus=100; %upper boundary, value b
bopt=0.1; %starting value
countb=0; % count iteration steps for value b
while abs(ap-ap_plus)>0.00001 %I need the value aopt where ap-ap_plus is close to zero, so I %can't use aopt in the condition
ap=ap_plus;
ap_plus=-tanh(aopt)+coth(bopt);%-tanh(aopt)--> -1, coth(bopt)-->1
while abs(bp-bp_plus)>0.00001
bp=bp_plus;
bp_plus=1+tanh(-bopt)+1/aopt+acoth(aopt*bopt); %tanh(-bopt)-->-1 acoth(aopt*bopt)-->0
bopt=bopt+0.1 %After each iteration the new estimate of bopt is increased +0.1, %assumes that the initial bopt is the lowest boundary
countb=countb+1; %count iteration
coll_countb(countb)=abs(bp_plus-bp); %collect differences
end
aopt=aopt+0.1 %see above
counta=counta+1;
coll_counta(counta)=abs(ap_plus-ap);
end
counta_coll=[1:counta]; %array of iteration steps
countb_coll=[1:countb];
plot(counta_coll, coll_counta, 'pk', countb_coll,coll_countb,'or')
legend('convergence of a', 'convergence of b')
The convergence is quite good, of course, due to the functions chosen...
The problem: However, after the inner loop is solved and an optimised value bopt is determined, this value is taken to the next equation, and so forth until the outer while loop is reached. So, as the functions ap_plus and bp_plus share the same variables, I'd like the inner while loop to be run again or as to say, ap_plus and bp_plus need to be solved simultaniously. How to do? Are there any other Matlab-embedded alternatives? I tried quite some combinations of the location of the variable definition or adding the same witing something like while abs(ap-ap_plus)>0.00001 && while abs(bp-bp_plus)>0.00001 but neither works. I also thought about 'parfor' but as the functions are dependend on each other, apparently it can't be applied (according to mathworks).
The real problem is a bunch of equations that need to be solved numerically (e.g. due to integrals that can't be solved analytically), so I have to go for iteration solutions and can't use 'solve' or the like.
Kind regards and thanks!

Réponse acceptée

Alan Weiss
Alan Weiss le 21 Oct 2014
If you have Optimization Toolbox you might find the fsolve function to be helpful. Be careful, you might need larger-than-default finite differences, as explained here.
If you don't have Optimization Toolbox, then you might just use the fminsearch function to look for a minimum of the sum of squares of the components of your function, somewhat like this curve-fitting example.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 commentaires
Alan Weiss
Alan Weiss le 22 Oct 2014
Instead of minimizing a function that goes to -Inf, minimize the sum of squares (or just the square if it is a scalar). This will have fminsearch aim for zero.
Alan Weiss
MATLAB mathematical toolbox documentation
Magnus
Magnus le 24 Oct 2014
looks like it's working. thanks, Alan!

Connectez-vous pour commenter.

Plus de réponses (1)

Magnus
Magnus le 22 Oct 2014
Dear Alan, thanks for your quick respond! fminsearch might work. I had a deeper look at the problem and the code. Apparently, my function runs towards -inf. Is there a termination condition that makes fminsearch stop and return the values when the function value is close to zero? I can only find ways to alter the iteration steps.
Kind regards,

Catégories

En savoir plus sur Programming 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!

Translated by