How to use a Loop in an optimization problem?
Show older comments
Hi everyone, I'm trying to find out an optimal capital structure, which means to find out the optimal variable c that maximizes -g(c). In order to do that I need first to solve a nonlinear system, which is my function Fun(x), for a given initial c0 and x0. Then using the optimal value x, I can find the value c that maximizes the -g(c). My problem is that I want to make a loop that stops when the value of c using in the nonlinear system is the same that the obtained value from the maximization problem, but everything I try it's not working.
My main code is:
function [x,c,err]=newdim3(Fun,x0,c0,~)
global xi tau_e tau_i r mu k epsilon;
tol=10^(-3);
c=c0;
x=x0;
for j=1
options=optimset('MaxFunEvals',1E5,'MaxIter',1E5,...
'TolFun',1E-32,'TolX',1E-32,'TolCon',1E-32);
[y,fval]=fmincon(@(y) Fun(y),x,[],[],[],[],...
[0 1 -Inf -Inf -Inf -Inf],[1 Inf Inf Inf Inf Inf],[],options);
a1=y(3);a2=y(4);b1=y(5);b2=y(6);
if (c>1)
tau_e3=tau_e*epsilon;
else
tau_e3=tau_e;
end
options=optimset('Display','iter','TolFun',1e-8);
g = @(C,y) -xi*((1-tau_e3)*((1/(r-mu))-(C/r))+...
a1+a2+(1-k)*(((1-tau_i)*C/r)+b1+b2));
C = fminbnd(@(C) g(C,x),0,y(2),options);
err=abs(C-c);
relerr=err/(abs(C)+tol);
if (err<tol|relerr<tol)
c=C;
break;
end
c=C;
x=y;
iter=j;
end
return
Answers (0)
Categories
Find more on Get Started with Optimization Toolbox 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!