Convergence program stuck at a point.
Show older comments
Hi all,
Below is the code when I am trying to get convergence of a function by varying a variable which dictates it. The sum of variables is a fixed constant. i.e a+b = a_initial. The issue I am facing is after some iterations a_old=a_older and b_old=b_older and the new values don't update. I know that there is a fix for this but somehow I am unable to fix it. Any help would be appreciated.
a_initial = M_f_b_i;
a_older = M_f_b_i; % initial guess for a
b_older = 0;% intial guess for b
tolerance = 1e-1; % tolerance for the convergence
b_old = (a_older+b_older)/2;
a_old = M_f_b_i-b_old;
kb = get_curvature_bending(a_old,Eb);
kr = get_curvature_rotating(b_old,Er);
i=1;
while abs(kb-kr)>tolerance
if kb>kr %
b_new = (b_old+a_old)/2;
a_new = (a_initial-b_new);
kb = get_curvature_bending(a_new,Eb);
kr = get_curvature_rotating(b_new,Er);
i=i+1;
a_older = a_old;
b_older = b_old;
a_old = a_new;
b_old = b_new;
else
b_new = (b_old+b_older)/2;
a_new = (a_initial-b_new);
kb = get_curvature_bending(a_new,Eb);
kr = get_curvature_rotating(b_new,Er);
i=i+1;
a_older = a_old;
b_older = b_old;
a_old = a_new;
b_old = b_new;
end
sprintf('Iteration number: %d',i)
end
end_curvature = kb;
Moment_f_b = a_new;
Moment_f_r = b_new;
end
Accepted Answer
More Answers (0)
Categories
Find more on Waveform Design and Signal Synthesis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!