Index in position 1 exceeds array bounds (must not exceed 1). Error in pij (line 14) pmat(k,n) = pis(k,1) .* tau(k,n); Error in pfij (line 18)

Please my code is not running when I run the main script GE_fsolve. I can attached my main codes upon request. At the moment I inserted copies of all functions that I am using. Please kindly help me with this. Thanks!!!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create output price function
function [Pis] = pis(wis)
global Ais beta IOcoef Nsec Ncoun
% reformat IOcoef to (NS,S) instead of the initial (NS,NS)
IOmat_cs_s = nan(Ncoun*Nsec,Nsec); %cs-s
for t = 1:1:Nsec
IOmat_cs_s(:,t) = sum(IOcoef(:,((t-1)*Ncoun+1):Ncoun*t),2); %cs-s
end
IOmat_cs = sum(IOmat_cs_s,2); %change IOcoef to (NS,1) instead of (NS,S)
% create matrix
pimat = zeros(Nsec*Ncoun,1);
% compute pis(NS,1)
for i = 1:1:Nsec*Ncoun
pimat(i) = ((beta(i)).^(-beta(i)) .* (1-beta(i)).^(-1+beta(i)))...
.*(wis(i).^beta(i) .* (IOmat_cs(i).*PMis(pij(pis(i)))).^(1-beta(i)))./Ais(i);
end
Pis = pimat; %(NS,1)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create pirce of output function
function [Pij] = pij(pis)
global tau Nsec Ncoun
% create matrix
pmat = zeros(Nsec*Ncoun,Ncoun);
% solve for price of output(n,k)
for k = 1:1:Nsec*Ncoun
for n = 1:1:Ncoun
pmat(k,n) = pis(k) .* tau(k,n);
end
end
Pij = pmat; %(NS,N)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create CES final demand function
function [Fij] = fij(pis,wis,mij)
global alpha sigma Nsec Ncoun
% PFis = PFis(pij,sigma,Ncoun,Nsec)
% reformat sigma to (N*S,1) instead of initial (S,1)
for s = 1:1:Nsec
idx = 1+(s-1)*Ncoun:1:Ncoun*s; %for every s what is idx
SG(idx,1) = ones(Ncoun,1)*sigma(s); %for every s use the respective idx as row and multiply the actual s value by col vector
end
% create matrices
fmat = zeros(Nsec*Ncoun,Ncoun);
for i = 1:1:Nsec*Ncoun
for j = 1:1:Ncoun
fmat(:,:) = alpha(i,j) .* (pij(pis(i,1))).^(-(SG*ones(1,Ncoun)))...
.*(PFis(pij(pis(i,1)))).^((SG*ones(1,Ncoun))-1) .* Yis(wis,pis,mij);
end
end
Fij = fmat; %(NS,N)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create CES intermediate demand function
function [Mij] = mij(pis,mij)
global gama rho Nsec Ncoun
% reformat rho to (N*S,1) instead of initial (S,1)
for s = 1:1:Nsec
idx = 1+(s-1)*Ncoun:1:Ncoun*s; %for every s what is idx
SG(idx,1) = ones(Ncoun,1)*rho(s); %for every s use the respective idx as row and multiply the actual s value by col vector
end
% create matrices
mmat = zeros(Nsec*Ncoun,Nsec*Ncoun);
for i = 1:1:Nsec*Ncoun
for j = 1:1:Ncoun
mmat(i,j) = gama(i,j) .* (pij(pis(i,1))).^(-(SG*ones(1,Ncoun)))...
.* (PMis(pij(pis(i,1)))).^((SG*ones(1,Ncoun))-1) .* IMis(pis,mij); %(NS,N)
end
end
Mij = mmat; %(NS*N)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create final demand total value of imports
function [Pfij] = pfij(pis,wis,mij)
global alpha sigma Nsec Ncoun
% reformat sigma to (N*S,1) instead of initial (S,1)
for s = 1:1:Nsec
idx = 1+(s-1)*Ncoun:1:Ncoun*s; %for every s what is idx
SG(idx,1) = ones(Ncoun,1)*sigma(s); %for every s use the respective idx as row and multiply the actual s value by col vector
end
% create matrices
pfmat = zeros(Nsec*Ncoun,Ncoun);
for i = 1:1:Nsec*Ncoun
for j = 1:1:Ncoun
pfmat(:,:) = alpha(i,j) .* (pij(pis(i,1))).^(1-(SG*ones(1,Ncoun)))...
.*(PFis(pij(pis(i,1)))).^(1-(SG*ones(1,Ncoun))) .* Yis(wis,pis,mij);
end
end
Pfij = pfmat; %(NS,N)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create intermediate demand total value of imports
function [Pmij] = pmij(pis,mij)
global gama rho Nsec Ncoun
% reformat rho to (N*S,1) instead of initial (S,1)
for s = 1:1:Nsec
idx = 1+(s-1)*Ncoun:1:Ncoun*s; %for every s what is idx
SG(idx,1) = ones(Ncoun,1)*rho(s); %for every s use the respective idx as row and multiply the actual s value by col vector
end
% create matrices
pmmat = zeros(Nsec*Ncoun,Nsec*Ncoun);
for i = 1:1:Nsec*Ncoun
for j = 1:1:Ncoun
pmmat(i,j) = gama(i,j) .* (pij(pis(i,1))).^(1-(SG*ones(1,Ncoun)))...
.* (PMis(pij(pis(i,1)))).^(1-(SG*ones(1,Ncoun))) .* IMis(pis,mij); %(NS,N)
end
end
Pmij = pmmat; %(NS,N)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Solve GE Model
function syseqn = GEsol(x)
global Ais Lis beta IOmat_cs Ncoun
% Define unknown variables x
% Break x into 4 separate variables
% System x=( mij, fij, pis, wi )
% (N*S,N*S) (N*S,N) (N*S,1) (NS,1)
mij = x(:,1:Ncoun);
fij = x(:,Ncoun+1:end-2);
pis = x(:,end-1);
wis = x(:,end);
% Safeguard restrictions
tol = 1e-10; %Tolerance, use to keep certain variables away from zero
mij = max(mij, tol);
fij = max(fij, tol);
pis = max(pis, tol);
wis = max(wis, tol);
% Equations to be solve simultaneously
eq1 = pij(pis).*fij - pfij(pis,wis,mij); %final demand import
eq2 = pij(pis).*mij - pmij(pis,wis,mij); %intermeditate demand import
eq3 = pis - (beta.^(-beta).*(1-beta).^(-1+beta))...
.* (wis.^beta .* (IOmat_cs.*PMis(pij(pis))).^(1-beta))./Ais; %output price equation
eq4 = Lis - (((sum(fij,2) + sum(mij,2)))./Ais) * ((beta.*PMis(pij(pis)))./...
((1-beta)*wis)).^(1-beta); %labor market clearing condition
syseqn = [eq1, eq2, eq3, eq4];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main Script PrograM
% ***********************************
close all;
clear;
clc;
tic;
global alpha gama sigma rho tau Ais Lis beta IOcoef IOmat_cs Nsec Ncoun
%******************************************
% Define country-sector inputs %
%******************************************
Nsec = 2;
Ncoun = 4;
%******************************************
% Define parameters %
%******************************************
sigma = 5*ones(Nsec,1); %elasticity of substitution for households
rho = 5*ones(Nsec,1); %elasticity of substitution for firm
beta = 0.6*ones(Nsec*Ncoun,1); %value-added share
Lis = 1*ones(Nsec*Ncoun,1); %labor (supply) endowment
Ais = 1*ones(Nsec*Ncoun,1); %TFP
tau = 1.5*ones(Nsec*Ncoun,Ncoun); %tariff
alpha = 0.6*ones(Nsec*Ncoun,Ncoun); %sector share of expenditure for final demand
gama = 0.4*ones(Nsec*Ncoun,Ncoun); %sector share of expenditure for intermediate demand
IOcoef = importdata('IOcoef.txt');
% reformat IOcoef to (NS,S) instead of the initial (NS,NS)
IOmat_cs_s = nan(Ncoun*Nsec,Nsec); %cs-s
for t = 1:1:Ncoun
IOmat_cs_s(:,t) = sum(IOcoef(:,((t-1)*Nsec+1):Nsec*t),2); %cs-s
end
IOmat_cs = sum(IOmat_cs_s,2); %change IOcoef to (NS,1) instead of (NS,S)
% % parameters put in a vector to enable easy passing to the function
% P = [beta,Lis,Ais,IOcoef];
%******************************************
% Solve non-linear equations(fsolve) %
%******************************************
options = optimset('Display', 'iter', 'MaxFunEvals', 20000, 'MaxIter', 20000, 'TolFun', 1e-10, 'TolX', 1e-10);
% initial guess vakues for x matrix
x0 = 0.5.*ones(8,10);
% call output of equation function under initial guess
% syseqn = GEsol(x0,P);
% syseqn = GEsol(x0,P,Nsec,Ncoun);
syseqn = GEsol(x0);
% fsolve solves the function by looking for matrix x0 using initial guess
% x = fsolve('GEsol', x0, options,P);
x = fsolve('GEsol', x0, options);
% solution of the model in terms of x
mij = x(:,1:Ncoun);
fij = x(:,Ncoun+1:end-2);
pis = x(:,end-1);
wis = x(:,end);

55 comentarios

hello
I had some trouble to run your code
  • first issue : error here : IOcoef = importdata('IOcoef.txt'); : the file IOcoef.txt is not provided
  • second issues : you have variable names like fij , pis and alike , which are the same as some of your subfunctions names :
% solution of the model in terms of x
mij = x(:,1:Ncoun);
fij = x(:,Ncoun+1:end-2);
pis = x(:,end-1);
wis = x(:,end);
conflict with subfunctions names , like :
function [Pis] = pis(wis)
this is not good and you should create subfunctions which names are not same as variables
for example i simply added "my" to the function names , like here :
function [Pis] = mypis(wis)
  • last but not least , where are all those subfunctions used in your main code ? are you sure you posted the entire code ?
all the best
Thanks for the response Mathieu, I will definitely correct all the errors i have made. But please I need to submit a results on this code by Sunday, is it possible to help me in running the code again, just to be sure I am doing the right thing. The main goal is to solve for these 4 unknown variables: [mij, fij, pis, wis], Below are the sizes of each variable.
fij: (Nsec*Ncoun,Ncoun)
mij: (Nsec*Ncoun,Ncoun)
pis: (Nsec*Ncoun,1)
wis: (Nsec*Ncoun,1)
Nsec is number of sectors and Ncoun is number of countries.
Please find attached the link to my drive specifically containing all the codes and the necessary data.
Hope to get a response soon.
Please can you check my code for me again, as I keep getting error and not able to obtain the unknown variables.
The main goal is to solve for these 4 unknown variables: [mij, fij, pis, wis], Below are the sizes of each variable.
fij: (Nsec*Ncoun,Ncoun)
mij: (Nsec*Ncoun,Ncoun)
pis: (Nsec*Ncoun,1)
wis: (Nsec*Ncoun,1)
Nsec is number of sectors and Ncoun is number of countries.
Please find attached both the zip file of my codes and the link to my drive specifically containing all the codes and the necessary data.
I made changes to my functions but the code is still not running, it stops with error "index exceeds number of array elements". Please can you check it for me. I have attached the my codes in the zip file and also the link to it directly in my google drive. The main goal is to solve for these 4 unknown variables: [mij, fij, pis, wis], Below are the sizes of each variable.
fij: (Nsec*Ncoun,Ncoun)
mij: (Nsec*Ncoun,Ncoun)
pis: (Nsec*Ncoun,1)
wis: (Nsec*Ncoun,1)
Nsec is number of sectors and Ncoun is number of countries.
Please find attached both the zip file of my codes and the link to my drive specifically containing all the codes and the necessary data.
Look in mypfij
for i = 1:1:Nsec*Ncoun
for j = 1:1:Ncoun
pfmat(:,:) = alpha(i,j) .* (mypij(mypis(i,1))).^(1-(SG*ones(1,Ncoun)))...
i is a scalar, so mypis(i,1) is a scalar, so you are passing a scalar to mypij . But mypij does
for k = 1:1:Nsec*Ncoun
for n = 1:1:Ncoun
pmat(k,n) = mypis(k) .* tau(k,n);
end
end
so it is expecting a vector of values to be passed in.
Both mypfij and mypij are expecting to process the entire vector; you need to change that so that only one of them processes the entire vector.
@Walter Roberson Thanks for the response, I will try to change it and see if it works. Please I am still new to matlab, do you mind changing it into vector form for me. Just to see how it works or is supposed to be like. Thanks.
Sorry, not enough documentation to be able to tell what needs to be changed.
Hello, Please I did everything but still couldn't solve for the unknown variables. I keep getting the below error when I run the GE_fsolve script. I have attached the new documentation.
Out of memory. The likely cause is an infinite recursion within the program.
Error in mypij (line 14)
pmat(:,n) = mypis(wis(:,1)) .* tau(:,n);
The main goal is to solve for these 4 unknown variables: [mij, fij, pis, wis], Below are the sizes of each variable.
fij: (Nsec*Ncoun,Ncoun)
mij: (Nsec*Ncoun,Ncoun)
pis: (Nsec*Ncoun,1)
wis: (Nsec*Ncoun,1)
Nsec is number of sectors and Ncoun is number of countries.
hello
your code is not very easy to debugg , but I could see already a couple of issues :
probably the most annoying one - as far as I understand how you constructed the whole thing :
  • so we start with the main code (GE_fsolve.m) , and first subfunction called is GEsol.m
  • in GEsol.m , there are these lines
% Equations to be solve simultaneously
eq1 = mypij(wis).*fij - mypfij(wis,mij); %final demand import
eq2 = mypij(wis).*mij - mypmij(wis,mij); %intermeditate demand import
eq3 = pis - (beta.^(-beta).*(1-beta).^(-1+beta))...
.* (wis.^beta .* (IOmat_cs.*myPMis(mypij(wis))).^(1-beta))./Ais; %output price equation
eq4 = Lis - (((sum(fij,2) + sum(mij,2)))./Ais) * ((beta.*PMis(pij(wis)))./...
((1-beta)*wis)).^(1-beta); %labor market clearing condition
where we call the subfunction mypij.m , (not only) and this function calls mypis.m
(BTW why the index k is no more used in the computation ? )
% solve for price of output(k,n)
for k = 1:1:Nsec*Ncoun
for n = 1:1:Ncoun
pmat(:,n) = mypis(wis(:,1)) .* tau(:,n);
end
end
and mypis.m then use again mypij.m .... this cannot work !
% compute pis(NS,1)
for i = 1:1:Nsec*Ncoun
pimat(:,1) = ((beta(:,1)).^(-beta(:,1)) .* (1-beta(:,1)).^(-1+beta(:,1)))...
.*(wis(:,1).^beta(:,1) .* (IOmat_cs(:,1).*myPMis(mypij(wis(:,1))))...
.^(1-beta(:,1)))./Ais(:,1);
end
so we have a problem here; a subfunction cannot call herself even through another (intermediate) subfunction
this could be the root cause of your infinite loop - or - matlab is stucked in this impossible scenario;
Thanks for the response, but I think I still don't understand what you mean by subfunctions cannot call herself even through another intermediate subfunction. I will appreciate if you show examples as I am not that experienced with matlab.
Please provide an example of what it should look like, or how I should create the function and call it to be used.
mypis:
% compute pis(NS,1)
for i = 1:1:Nsec*Ncoun
pimat(:,1) = ((beta(:,1)).^(-beta(:,1)) .* (1-beta(:,1)).^(-1+beta(:,1)))...
.*(wis(:,1).^beta(:,1) .* (IOmat_cs(:,1).*myPMis(mypij(wis(:,1))))...
.^(1-beta(:,1)))./Ais(:,1);
end
Notice the call to mypij in the first of the continuation lines
Meanwhile, mypij has
for k = 1:1:Nsec*Ncoun
for n = 1:1:Ncoun
pmat(:,n) = mypis(wis(:,1)) .* tau(:,n);
end
end
Notice the call to mypis() .
So to compute mypis the code needs to call mypij, but to compute mypij you need to call mypis, which needs to call mypij which needs to call mypis, which ... etc.
In some cases it is possible to write routines that depend upon each other -- but in such cases you need to be able to prove that each one of them will eventually terminate, such as if each iteration the array size becomes smaller than the time before.
@Mathieu NOE's reply was not present when I wrote mine... not sure why it did not show up.
An example of something that does not work:
function C = A(x)
C = B(x-1);
end
function D = B(x)
D = A(x-1);
end
In order to execute A, you need to finish executing a call to B. In order to finish executing a call to B, you need to finish executing a call to A -- but in order to finish that call to A, you need to call B to call A to call B to ... it never ends until MATLAB says you are out of memory or you have made too many calls.
An example of something that does work
function C = A(x)
C = B(x-1);
end
function D = B(x)
if all(isinf(x) | x < 0)
D = max(-2, x);
else
D = A(x-1);
end
end
For example, call A([2 4]) then that calls B([1 3]) . In B, no values of [1 3] are infinite or negative, so you take the else and call A([0 2]) . A then calls B([-1 1]) . None of the elements of [-1 1] are infinite, and at least one of the values is not < 0, so the else is taken and A([-2 0]) is called. A then calls B([-3 -1]) . None of the elements of [-3 -1] are infinite, but all of the values of [-3 -1] are < 0, so the if is taken. max(-2, [-3 -1]) is [-2 -1] and that is the output, so that call to B with [-3 -1] finishes, and returns to A, which finishes and returns to the B instance processing [-1 1], which finishes and returns to A, which finishes and returns to the B that is processing [1 3], which returns to the A that is processing [2 4], which finishes -- and the final output is [-2 -1] .
So the problem is not having one function calling another and the other calling the first: the problem is that you have to hae some condition in at least one of the function under which the calls terminate. Each cycle of calls must, in some sense, be reducing the amount of remaining work, and then at some point the calls have to detect that there is no remaining work and return back values.
However... as outsiders we have to ask whether mypis() really depends upon mypij() and mypij() really depends upon mypis() . Sorry, but at the moment as an outsider I get the impression that you are flailing around trying things without thinking through questions about which routine needs to process vectors and which routines need to process invididual elements.
We cannot make any recommendations for you because there is not enough documentation about what the code is intended to do, or why you have those multiple layers of calls.
hello again
I don't know what the code is supposed to do (as most of the time when you are not expert in the specific topic)
but if I were you I would first make a graph to show how should the data flow be organized - and avoid this situation.
Try to make the whole process simpler like :
  • one main function call one or several subfunctions , that can work in parallel but are not dependent one each other
  • if you really needs several hierarchical levels , a subfunction of level -1 can call a subfunction of level -2 , which can also call a subfunction of level -3 , etc... but the problem that we see in your code is that you create a kind of algebraic loop that cannot be solved : a first subfunction call a second subfunction that call itself the first subfunction. That is simply not good coding practice ...
If I had a lot of free time , I could try rewritte your program , but I need to see how the data flow is / should be organized, where we start, what we need to compute (some infos about the whole process would be needed), etc...
so this can be a lot of work and even if I am also keen to give a hand within the possibilities of my skills and agenda, I will not promise to solve all issues for tomorrow !
Thanks for the feedback, I will try and incorporate all the feedback. I agree my model is complicated to solve, that is why I need help from you all, as it is beyond my own coding skills. I realized you both have the same feedback on my code. Moreover, my background is in economics and I am not perfectly excellent at coding, I am still improving on that.
Summary of what I am trying to achieve and the details involved. I want to solve for the price (pis) of output (qis), wages (wis), final demand(fij), intermediate demand(mij).
*The price(pis) is a function of wage(wis) and a function of price index(PMis).
*Now if this output is purchased by another country, then that couuntry will be charged for the price of the output plus the import tariff, this new price then becomes pij. So pij is a function of pis and tariff(tau).
*Now this output purchased is either consumed or use as intermediate input by the country buying it.
*If is used as final consumption, then its demand function is fij, which is a function of pij, PFis, and Yis.
*PFis is similar to PMis, which are all price index, and they depend on pij not pis, but pij depends on pis, and pis depend on wis and PMis.
*Yis is the total income which is a function of wis, total labor endowment (Lis), and total revenue (TRis).
*TRis is the revenue generated from the import tariff imposed by that country purchasing it, so is a function of (pis*fij*tau)+(pis*tau*mij).
*Now if this output is used as intermediate input, then its demand function is mij, which is a function of pij, PMis, and IMis.
*IMis is the total value of the intermediate input used; which is sourced across all sectors of a country, and it is a function of mij and PMis.
*So to solve for the 4 unknown variables, I need to solve the 4 equations in the GEsol, where equation1 solves fij (NS,N) iteratively, equation 2 solves mij (NS,N) iteratively, equation 3 solves pis (NS,1) iteratively and equation 4 solves wis(NS,1) iteralively. But these variables are functions of each other and solves simultaneously.
N is the same Ncoun (countries) and S is the same Nsec (sectors).
So I want to solve one matrix for all these unknown variables then disintegrate them. That is why I have the initial guess as:
% initial guess vakues for x matrix
x0 = 0.5.*ones(8,10);
% solution of the model in terms of x
mij = x(:,1:Ncoun);
fij = x(:,Ncoun+1:end-2);
pis = x(:,end-1);
wis = x(:,end);
*the rows are the same, which is N*S; and the first N cols is for fij, then second N cols is for mij, the last but one col is for pis, and the final col is for wis.
Please I have attached the equations to be solved and I will be happy if you can check it again Maybe I will have to change everything, which I am ready to do.
Hope to hear from you all soon.
Thanks,
Celestine.
Hello Please can I get help on my coding issue below.
Thanks for the feedback, I will try and incorporate all the feedback. I agree my model is complicated to solve, that is why I need help from you all, as it is beyond my own coding skills. I realized you both have the same feedback on my code. Moreover, my background is in economics and I am not perfectly excellent at coding, I am still improving on that.
Summary of what I am trying to achieve and the details involved. I want to solve for the price (pis) of output (qis), wages (wis), final demand(fij), intermediate demand(mij).
*The price(pis) is a function of wage(wis) and a function of price index(PMis).
*Now if this output is purchased by another country, then that couuntry will be charged for the price of the output plus the import tariff, this new price then becomes pij. So pij is a function of pis and tariff(tau).
*Now this output purchased is either consumed or use as intermediate input by the country buying it.
*If is used as final consumption, then its demand function is fij, which is a function of pij, PFis, and Yis.
*PFis is similar to PMis, which are all price index, and they depend on pij not pis, but pij depends on pis, and pis depend on wis and PMis.
*Yis is the total income which is a function of wis, total labor endowment (Lis), and total revenue (TRis).
*TRis is the revenue generated from the import tariff imposed by that country purchasing it, so is a function of (pis*fij*tau)+(pis*tau*mij).
*Now if this output is used as intermediate input, then its demand function is mij, which is a function of pij, PMis, and IMis.
*IMis is the total value of the intermediate input used; which is sourced across all sectors of a country, and it is a function of mij and PMis.
*So to solve for the 4 unknown variables, I need to solve the 4 equations in the GEsol, where equation1 solves fij (NS,N) iteratively, equation 2 solves mij (NS,N) iteratively, equation 3 solves pis (NS,1) iteratively and equation 4 solves wis(NS,1) iteralively. But these variables are functions of each other and solves simultaneously.
N is the same Ncoun (countries) and S is the same Nsec (sectors).
So I want to solve one matrix for all these unknown variables then disintegrate them. That is why I have the initial guess as:
% initial guess vakues for x matrix
x0 = 0.5.*ones(8,10);
% solution of the model in terms of x
mij = x(:,1:Ncoun);
fij = x(:,Ncoun+1:end-2);
pis = x(:,end-1);
wis = x(:,end);
*the rows are the same, which is N*S; and the first N cols is for fij, then second N cols is for mij, the last but one col is for pis, and the final col is for wis.
Please I have attached the equations to be solved and I will be happy if you can check it again Maybe I will have to change everything, which I am ready to do.
Hope to hear from you all soon.
Thanks,
Celestine.
hello Celestine
wish I could help you, but once I started to read your manuscript I got terrible headaches... this is not simple as I am absolute rookie in economic science.... maybe it would be easier if you could rewritte it with some simpler variable names instead of these cryptic anotations with ij everywhere
also could try to make a graphic to show the work flow of your data vs a time axis ?
Thanks for the response, I will do that and rewrite everything. Please can you explain the graphical part for me, in terms of data vs time axis. I don't understand. I think you explaining it better will help me a lot to come out with a nice flow.
well , I meant , some very high level desription of the tasks and how they interact , especially if there are recurrence
it can be as simple as a pseudo code first like :
  1. initialization
  2. C = A + B
  3. D = D + C (update D)
  4. A = A + 1 (update A)
  5. B = B/2 (update B)
  6. jump back to step 1 and do it until tbd condition (will be a for or while loop or I don't know...)
@Mathieu NOE Thanks for the response. I think I now understand what you mean. Let me rewirte everything and send it to you in few hours. But I will appreciate if the coding can be around what I have already done with some changes, if is possible. But if not, I am ok with how you change it.
Hello all, Please I have attached a better explanation of my model. I will appreciate if you can look at what I have already recoded and see if there should be some changes instead of changing everything. I believe my problem has to do with writing and using the function and subfunctions in their right place, and also with size issues of matrix. Please I really really need help on this as I feel so stuck and still not experienced with matlab.
Thanks,
Celestine.
hello Celestine
I will have a look and try further help you , but I am also in a busy period - I cannot make any promises about my chances of success and when I will be able to show some progress. Do my best I can
Hello all,
Please any help with my code, I just want to know where the bugs are and the proper way of calling my functions or writing the functions well, so that I can run the code and get my unknown variables. I am still working on it to correct but no success yet. Please i will appreciate if of you can look at my codes in detail for me.
hello Celestine
I started to read your memo , but it's by no way an easy task - at least for me, especially the relationships in this economic matter aren't very familiar to my ears.
I don't know if Walter could start doing something ?
I have no economics experience, and those are too many equations for me to get through.
Please I understand you don't have any economic background. What I am asking is for you to check the functions for me, and the calling of the function for me with some edit. I am not saying you should understand everything, as what I am after is the numerical excercise of my model. That is more of a coding issue than an economic issue. So please I will appreciate if you can just check my functions written, callimg function, and subfunctions for me.
I believe with that I will know where I got it wrong and will correct. Or possible if any other person can help me. I will appreciate.
Thanks
hello again
well it's not so easy - because IMHO we have today a code that does not work because of this "algebraic" loop where one function calls a subfunction which itself call the first one function (already explained above)
I doubt that this important issue can be solved simply by "checking" a few functions - it can be that the entire logic must be reviewed and corrected and you probably don't know how hard it can be to dig into someone else code , especially when it's so complex and not in a matter you master (so you also don't know what should be obtained as well )
I really hate to say that I am not in a position to help , it's not a question of ego , but when I start something I like to succeed (as anyone) ---- but believe me , this task is really not easy at all... I could spend hours and hours on it , but this time I simply don't have now. Really sorry
I checked the functions and how they are called and I already reported back that your code won't work and pointed to the lines that are the problem.
Your code needs to be redesigned, so at this point having me look at it means that I would have to study the equations and the design outline that you posted and figure out what would have to be done.
Please can you help me in redesigning the codes then. I will appreciate that. I am working it but still no success at the moment.
Thanks.
Sorry, I do not have the resources to engage in a redesign.
Sounds good, let me keep trying and see if I can come up with a better code.
Try to make the whole process simpler like :
  • one main function call one or several subfunctions , that can work in parallel but are not dependent one each other
  • if you really needs several hierarchical levels , a subfunction of level -1 can call a subfunction of level -2 , which can also call a subfunction of level -3 , etc... but the problem that we see in your code is that you create a kind of algebraic loop that cannot be solved : a first subfunction call a second subfunction that call itself the first subfunction. That is simply not good coding practice ...
Base on the first statement you made, what do you mean by one main function call one or several subfunctions and that work in parallel but are not dependent on each other. Please can you explain that for me. I want to try that approach as my other methods aint working still.
Please can you explain this well for me, the first bullet.
Try to make the whole process simpler like :
  • one main function call one or several subfunctions , that can work in parallel but are not dependent one each other
  • if you really needs several hierarchical levels , a subfunction of level -1 can call a subfunction of level -2 , which can also call a subfunction of level -3 , etc... but the problem that we see in your code is that you create a kind of algebraic loop that cannot be solved : a first subfunction call a second subfunction that call itself the first subfunction. That is simply not good coding practice ...
hello Celestine
about the first bullet - this is just a basic coding practice , when you hav a complex task you try to split it in small pieces (simpler); applied to coding, this means you try to split your complex task into a main code that contains mostly :
  • initialising data / structures
  • call subfunctions ( that do the hard work )
  • put together the results of the subfunctions - the way you want it
  • eventually plot and export the results
that "main" code is supposed to be simple and easy to create , read and debugg. Even a non specialist should be able to follow the logic even if the maths or operations may not be his cup of tea.
now what is in the subfunctions depends of what has to be done. usually we put there what is complex or repetitive (so you can call the same subfunction multiple times , for example in a for loop).
to come back to the main issue in your code is that if I had two subfunctions , you have to avoid a situation where the first one calls the second which itself depends on the first one . This kind of situation usually lead to impredictable errors or matlab will simply "freeze" as this is not resolvable.
that 's why in one of my previous answer I say that if yiu are in trouble with this situation you should start to think how the data flow must be organized to avoid such kind of "algebraic" loop; once this is clear for you, then the code implementation should be easier to do and to debug;
hope this general statements can help
you have to avoid a situation where the first one calls the second which itself depends on the first one .
Not exactly -- but if you do have your code work that way, then each time you go through the sequence, there has to be some way in which you are getting closer to finishing, and the code must test for that completion.
When I glanced at the information earlier, it looked to me as if you should perhaps be working with iteration:
  1. initialize first matrix
  2. loop:
  3. use current version of first matrix to generate second matrix
  4. use second matrix to propose a modified version of the first matrix
  5. if the proposed modified version of the first matrix is "close enough" to the current version of the first matrix, then say that the iteration is done and leave the loop
  6. otherwise, make the proposed modified version of the first matrix into the current version of the first matrix
  7. loop back
  8. end of loop
  9. the current version of the first matrix is the one you work with for whatever calculations
This does not use recursion, it uses looping, and it has an endpoint (provided that generation of the new matrices does not diverge.)
Thanks for the response. Please I did recode my model as you guys suggested, with just one big function,created matrices of all variables to be used in that function, and then wrote a script in a different file to solve everything.
Fsolve trys to solve but stopped premeturely. Below is the error message I get. I have also attached the two matlab files that I used. I simplify everytthing, so I believe this will be easier to read.
############################## Error Error Error
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 77 5.82884e+07 2.18e+06 1
1 154 3.49143e+07 1 1.71e+07 1
2 231 3.30203e+07 2.5 2.76e+07 2.5
3 308 3.18023e+07 0.111314 2.08e+07 2.5
4 385 3.12936e+07 0.115472 2.03e+07 2.5
5 462 3.08079e+07 0.12868 2.41e+07 2.5
6 539 3.01068e+07 0.136415 2.63e+07 2.5
7 616 2.86833e+07 0.124569 2.15e+07 2.5
8 617 2.86833e+07 0.147624 2.15e+07 2.5
9 694 2.70401e+07 0.0369061 1.1e+07 0.0369
10 771 2.62905e+07 0.0369061 2.18e+06 0.0369
11 848 2.56244e+07 0.0369061 2.72e+06 0.0369
12 925 2.42577e+07 0.0922652 9.3e+06 0.0923
13 1002 2.40633e+07 0.0766155 1.52e+07 0.0923
14 1079 2.36507e+07 0.0922652 2.21e+07 0.0923
15 1156 2.28286e+07 0.0849372 1.38e+07 0.0923
16 1233 2.25573e+07 0.0922652 2.29e+07 0.0923
17 1310 2.16469e+07 0.0845858 1.27e+07 0.0923
18 1387 2.14118e+07 0.0922652 2.26e+07 0.0923
19 1464 2.04906e+07 0.084304 1.18e+07 0.0923
20 1541 2.02376e+07 0.0922652 2.14e+07 0.0923
21 1618 1.93521e+07 0.084423 1.12e+07 0.0923
22 1695 1.90464e+07 0.0922652 1.98e+07 0.0923
23 1772 1.8223e+07 0.0847077 1.06e+07 0.0923
24 1849 1.785e+07 0.0922652 1.81e+07 0.0923
25 1926 1.70975e+07 0.0850699 1.01e+07 0.0923
26 2003 1.66549e+07 0.0922652 1.63e+07 0.0923
27 2080 1.59727e+07 0.0855859 9.66e+06 0.0923
28 2157 1.5462e+07 0.0922652 1.45e+07 0.0923
29 2234 1.48465e+07 0.0863511 9.2e+06 0.0923
30 2311 1.42701e+07 0.0922652 1.28e+07 0.0923
31 2388 1.37167e+07 0.0875094 8.75e+06 0.0923
32 2465 1.30766e+07 0.0922652 1.11e+07 0.0923
33 2542 1.26033e+07 0.0893298 8.37e+06 0.0923
34 2619 1.19747e+07 0.0922652 9.72e+06 0.0923
35 2696 1.15443e+07 0.0895756 7.79e+06 0.0923
36 2773 1.08928e+07 0.0922652 8.42e+06 0.0923
37 2850 1.04913e+07 0.0922652 7.35e+06 0.0923
38 2927 9.79987e+06 0.0922652 6.88e+06 0.0923
39 3004 9.38865e+06 0.0922652 6.5e+06 0.0923
40 3081 8.72899e+06 0.0922652 5.72e+06 0.0923
41 3158 8.28065e+06 0.0922652 5.48e+06 0.0923
42 3235 7.6779e+06 0.0922652 4.56e+06 0.0923
43 3312 7.18549e+06 0.0922652 4.32e+06 0.0923
44 3389 6.64283e+06 0.0922652 3.87e+06 0.0923
45 3466 6.11411e+06 0.0922652 3.23e+06 0.0923
46 3543 5.60509e+06 0.0922652 3.49e+06 0.0923
47 3620 5.0628e+06 0.0922652 2.51e+06 0.0923
48 3697 4.61104e+06 0.0922652 3.07e+06 0.0923
49 3774 4.17811e+06 0.0922652 2.04e+06 0.0923
50 3851 3.83192e+06 0.0922652 2.49e+06 0.0923
51 3928 3.47804e+06 0.0922652 1.92e+06 0.0923
52 3929 3.47804e+06 0.0922652 1.92e+06 0.0923
53 4006 3.30109e+06 0.0230663 1.05e+06 0.0231
54 4007 3.30109e+06 0.0576657 1.05e+06 0.0577
55 4084 3.21145e+06 0.0144164 6.75e+05 0.0144
56 4085 3.21145e+06 0.0360411 6.75e+05 0.036
57 4162 3.15874e+06 0.00901027 5.99e+05 0.00901
58 4163 3.15874e+06 0.0225257 5.99e+05 0.0225
59 4240 3.12681e+06 0.00563142 5.93e+05 0.00563
60 4317 3.04882e+06 0.0140786 5.79e+05 0.0141
61 4318 3.04882e+06 0.0351964 5.79e+05 0.0352
62 4319 3.04882e+06 0.0087991 5.79e+05 0.0088
63 4396 3.03725e+06 0.00219977 5.78e+05 0.0022
64 4473 3.00844e+06 0.00549943 9.38e+05 0.0055
65 4550 2.94755e+06 0.0130418 5.69e+05 0.0137
66 4551 2.94755e+06 0.0326044 5.69e+05 0.0326
67 4628 2.90414e+06 0.00815111 5.66e+05 0.00815
68 4629 2.90414e+06 0.0203778 5.66e+05 0.0204
69 4706 2.87711e+06 0.00509444 5.65e+05 0.00509
70 4707 2.87711e+06 0.0127361 5.65e+05 0.0127
71 4784 2.86027e+06 0.00318403 5.64e+05 0.00318
72 4861 2.81906e+06 0.00796007 1.4e+06 0.00796
73 4938 2.7996e+06 0.00450515 5.61e+05 0.0199
74 4939 2.7996e+06 0.0199002 5.61e+05 0.0199
75 5016 2.77343e+06 0.00497504 5.6e+05 0.00498
76 5017 2.77343e+06 0.0124376 5.6e+05 0.0124
77 5094 2.75731e+06 0.0031094 5.6e+05 0.00311
78 5095 2.75731e+06 0.0077735 5.6e+05 0.00777
79 5172 2.74737e+06 0.00194338 5.6e+05 0.00194
80 5249 2.72285e+06 0.00485844 6.91e+05 0.00486
81 5250 2.72285e+06 0.0121461 6.91e+05 0.0121
82 5327 2.7082e+06 0.00303652 8.11e+05 0.00304
83 5404 2.67483e+06 0.00759131 1.12e+07 0.00759
84 5481 2.673e+06 0.000245633 7.27e+05 0.019
85 5482 2.673e+06 0.0189783 7.27e+05 0.019
86 5559 2.64969e+06 0.00474457 5.58e+05 0.00474
87 5560 2.64969e+06 0.0118614 5.58e+05 0.0119
88 5637 2.63397e+06 0.00296536 5.57e+05 0.00297
89 5638 2.63397e+06 0.00741339 5.57e+05 0.00741
90 5715 2.62412e+06 0.00185335 5.57e+05 0.00185
91 5792 2.60559e+06 0.00463337 4.62e+07 0.00463
92 5869 2.60363e+06 6.75073e-05 4.49e+06 0.0116
93 5946 2.60238e+06 0.000309398 5.56e+05 0.0116
94 5947 2.60238e+06 0.0115834 5.56e+05 0.0116
95 6024 2.58836e+06 0.00289586 5.56e+05 0.0029
96 6101 2.55585e+06 0.00723964 2.37e+07 0.00724
97 6178 2.55352e+06 0.000155079 2.1e+06 0.0181
98 6255 2.54671e+06 0.00166526 8e+05 0.0181
99 6332 2.53964e+06 0.00183351 5.55e+05 0.0181
100 6333 2.53964e+06 0.0180991 5.55e+05 0.0181
101 6334 2.53964e+06 0.00452477 5.55e+05 0.00452
102 6411 2.53459e+06 0.00113119 5.55e+05 0.00113
103 6488 2.52223e+06 0.00282798 7.12e+05 0.00283
104 6565 2.49445e+06 0.00706996 5.66e+05 0.00707
105 6566 2.49445e+06 0.0176749 5.66e+05 0.0177
106 6643 2.47461e+06 0.00441872 8.41e+05 0.00442
107 6644 2.47461e+06 0.0110224 8.41e+05 0.011
108 6721 2.46316e+06 0.0027556 5.79e+05 0.00276
109 6722 2.46316e+06 0.00688901 5.79e+05 0.00689
110 6799 2.4553e+06 0.00172225 5.83e+05 0.00172
111 6800 2.4553e+06 0.00430563 5.83e+05 0.00431
112 6877 2.45045e+06 0.00107641 5.86e+05 0.00108
113 6954 2.4385e+06 0.00269102 5.93e+05 0.00269
114 7031 2.40998e+06 0.00672755 6.19e+05 0.00673
115 7032 2.40998e+06 0.0168189 6.19e+05 0.0168
116 7109 2.39065e+06 0.00420472 6.43e+05 0.0042
117 7110 2.39065e+06 0.0105118 6.43e+05 0.0105
118 7187 2.37905e+06 0.00262795 7.34e+05 0.00263
119 7264 2.35253e+06 0.00656987 1.08e+07 0.00657
120 7341 2.35074e+06 0.000242368 1.08e+06 0.0164
121 7418 2.3489e+06 0.00056724 6.19e+05 0.0164
122 7419 2.3489e+06 0.0164247 6.19e+05 0.0164
123 7496 2.33306e+06 0.00410617 5.97e+05 0.00411
124 7497 2.33306e+06 0.0102654 5.97e+05 0.0103
125 7574 2.32326e+06 0.00256636 5.84e+05 0.00257
126 7575 2.32326e+06 0.00641589 5.84e+05 0.00642
127 7652 2.31732e+06 0.00160397 5.76e+05 0.0016
128 7729 2.30337e+06 0.00400993 5.68e+05 0.00401
129 7730 2.30337e+06 0.0100248 5.68e+05 0.01
130 7807 2.29385e+06 0.00250621 5.7e+05 0.00251
131 7808 2.29385e+06 0.00626552 5.7e+05 0.00627
132 7885 2.28808e+06 0.00156638 7.01e+05 0.00157
133 7962 2.27556e+06 0.00391595 5.74e+05 0.00392
134 7963 2.27556e+06 0.00978987 5.74e+05 0.00979
135 8040 2.26615e+06 0.00244747 5.75e+05 0.00245
136 8041 2.26615e+06 0.00611867 5.75e+05 0.00612
137 8118 2.26032e+06 0.00152967 5.75e+05 0.00153
138 8119 2.26032e+06 0.00382417 5.75e+05 0.00382
139 8196 2.25674e+06 0.000956042 5.76e+05 0.000956
140 8273 2.24801e+06 0.0023901 1.23e+06 0.00239
141 8350 2.24437e+06 0.00129144 5.78e+05 0.00598
142 8351 2.24437e+06 0.00597526 5.78e+05 0.00598
143 8428 2.23868e+06 0.00149382 5.78e+05 0.00149
144 8429 2.23868e+06 0.00373454 5.78e+05 0.00373
145 8506 2.2352e+06 0.000933635 5.78e+05 0.000934
146 8583 2.22664e+06 0.00233409 7.7e+05 0.00233
147 8660 2.21511e+06 0.00372916 5.82e+05 0.00584
148 8661 2.21511e+06 0.0093229 5.82e+05 0.00932
149 8738 2.20617e+06 0.00233072 5.82e+05 0.00233
150 8739 2.20617e+06 0.00582681 5.82e+05 0.00583
151 8816 2.20062e+06 0.0014567 5.82e+05 0.00146
152 8817 2.20062e+06 0.00364176 5.82e+05 0.00364
153 8894 2.19721e+06 0.000910439 5.82e+05 0.00091
154 8971 2.19033e+06 0.0022761 3.14e+07 0.00228
155 9048 2.18911e+06 6.24281e-05 2.9e+06 0.00228
156 9125 2.18831e+06 0.000296249 5.83e+05 0.00228
157 9202 2.18202e+06 0.0022761 5.62e+07 0.00228
158 9279 2.18041e+06 4.53974e-05 5.54e+06 0.00228
159 9356 2.17978e+06 0.000164765 5.84e+05 0.00228
160 9433 2.17144e+06 0.0022761 5.85e+05 0.00228
161 9434 2.17144e+06 0.00569024 5.85e+05 0.00569
162 9511 2.16631e+06 0.00142256 9.84e+05 0.00142
163 9588 2.16063e+06 0.00194389 5.86e+05 0.00356
164 9589 2.16063e+06 0.00485972 5.86e+05 0.00486
165 9666 2.156e+06 0.00121493 5.86e+05 0.00121
166 9667 2.156e+06 0.00303733 5.86e+05 0.00304
167 9744 2.15312e+06 0.000759332 5.86e+05 0.000759
168 9821 2.14643e+06 0.00189833 3.12e+06 0.0019
169 9898 2.1457e+06 0.000261956 5.86e+05 0.00475
170 9899 2.1457e+06 0.00474582 5.86e+05 0.00475
171 9976 2.14139e+06 0.00118646 5.87e+05 0.00119
172 10053 2.13156e+06 0.00296614 5.88e+05 0.00297
173 10054 2.13156e+06 0.00741535 5.88e+05 0.00742
174 10131 2.12453e+06 0.00185384 5.88e+05 0.00185
175 10132 2.12453e+06 0.00463459 5.88e+05 0.00463
176 10209 2.12025e+06 0.00115865 5.88e+05 0.00116
177 10286 2.10966e+06 0.00289662 5.89e+05 0.0029
178 10287 2.10966e+06 0.00724155 5.89e+05 0.00724
179 10364 2.10331e+06 0.00181039 3.14e+06 0.00181
180 10441 2.10262e+06 0.000249701 5.89e+05 0.00453
181 10442 2.10262e+06 0.00452597 5.89e+05 0.00453
182 10519 2.09852e+06 0.00113149 5.89e+05 0.00113
183 10596 2.0892e+06 0.00282873 5.9e+05 0.00283
184 10597 2.0892e+06 0.00707183 5.9e+05 0.00707
185 10674 2.0825e+06 0.00176796 5.9e+05 0.00177
186 10675 2.0825e+06 0.00441989 5.9e+05 0.00442
187 10752 2.07843e+06 0.00110497 5.9e+05 0.0011
188 10829 2.06835e+06 0.00276243 5.91e+05 0.00276
189 10830 2.06835e+06 0.00690608 5.91e+05 0.00691
190 10907 2.0622e+06 0.00172652 1.73e+06 0.00173
191 10984 2.06077e+06 0.000547947 5.91e+05 0.00432
192 10985 2.06077e+06 0.0043163 5.91e+05 0.00432
193 11062 2.05679e+06 0.00107908 5.92e+05 0.00108
194 11139 2.04697e+06 0.00269769 5.92e+05 0.0027
195 11216 2.02475e+06 0.00674422 5.94e+05 0.00674
196 11217 2.02475e+06 0.0168606 5.94e+05 0.0169
197 11294 2.00873e+06 0.00421514 5.94e+05 0.00422
198 11295 2.00873e+06 0.0105378 5.94e+05 0.0105
199 11296 2.00873e+06 0.00263446 5.94e+05 0.00263
200 11373 2.00626e+06 0.000658615 5.94e+05 0.000659
201 11450 2.00104e+06 0.00164654 1.38e+07 0.00165
202 11527 2.00033e+06 8.15109e-05 1.01e+06 0.00165
203 11604 1.99598e+06 0.00152388 5.94e+05 0.00165
204 11605 1.99598e+06 0.0038097 5.94e+05 0.00381
205 11682 1.99238e+06 0.000952425 5.94e+05 0.000952
206 11683 1.99238e+06 0.00238106 5.94e+05 0.00238
207 11760 1.99014e+06 0.000595265 5.94e+05 0.000595
208 11837 1.98492e+06 0.00148816 2.46e+06 0.00149
209 11914 1.98416e+06 0.000295858 5.95e+05 0.00372
210 11915 1.98416e+06 0.00372041 5.95e+05 0.00372
211 11992 1.9808e+06 0.000930102 5.95e+05 0.00093
212 12069 1.97286e+06 0.00232526 5.95e+05 0.00233
213 12070 1.97286e+06 0.00581314 5.95e+05 0.00581
214 12147 1.96745e+06 0.00145328 5.95e+05 0.00145
215 12148 1.96745e+06 0.00363321 5.95e+05 0.00363
216 12225 1.96418e+06 0.000908303 5.96e+05 0.000908
217 12302 1.95643e+06 0.00227076 5.96e+05 0.00227
218 12303 1.95643e+06 0.00567689 5.96e+05 0.00568
219 12380 1.95115e+06 0.00141922 5.96e+05 0.00142
220 12381 1.95115e+06 0.00354806 5.96e+05 0.00355
221 12458 1.94795e+06 0.000887015 5.96e+05 0.000887
222 12535 1.94037e+06 0.00221754 5.97e+05 0.00222
223 12536 1.94037e+06 0.00554384 5.97e+05 0.00554
224 12613 1.93522e+06 0.00138596 5.97e+05 0.00139
225 12614 1.93522e+06 0.0034649 5.97e+05 0.00346
226 12691 1.9321e+06 0.000866225 5.97e+05 0.000866
227 12768 1.92455e+06 0.00216556 5.97e+05 0.00217
228 12769 1.92455e+06 0.00541391 5.97e+05 0.00541
229 12846 1.91961e+06 0.00135348 5.97e+05 0.00135
230 12923 1.90803e+06 0.00338369 5.98e+05 0.00338
231 12924 1.90803e+06 0.00845923 5.98e+05 0.00846
232 13001 1.9002e+06 0.00211481 5.98e+05 0.00211
233 13078 1.88163e+06 0.00528702 5.99e+05 0.00529
234 13079 1.88163e+06 0.0132175 5.99e+05 0.0132
235 13080 1.88163e+06 0.00330439 5.99e+05 0.0033
236 13157 1.87852e+06 0.000826097 5.99e+05 0.000826
237 13158 1.87852e+06 0.00206524 5.99e+05 0.00207
238 13235 1.87659e+06 0.000516311 5.99e+05 0.000516
239 13312 1.87216e+06 0.00129078 3.66e+06 0.00129
240 13389 1.87168e+06 0.000168612 5.99e+05 0.00323
241 13390 1.87168e+06 0.00322694 5.99e+05 0.00323
242 13467 1.86878e+06 0.000806735 5.99e+05 0.000807
243 13544 1.86186e+06 0.00201684 6e+05 0.00202
244 13545 1.86186e+06 0.00504209 6e+05 0.00504
245 13622 1.85721e+06 0.00126052 6e+05 0.00126
246 13699 1.84582e+06 0.00315131 6e+05 0.00315
247 13776 1.81971e+06 0.00787827 6.03e+05 0.00788
248 13777 1.81971e+06 0.0196957 6.03e+05 0.0197
249 13854 1.8011e+06 0.00492392 6.01e+05 0.00492
250 13855 1.8011e+06 0.0123098 6.01e+05 0.0123
251 13856 1.8011e+06 0.00307745 6.01e+05 0.00308
252 13933 1.79834e+06 0.000769363 6.01e+05 0.000769
253 14010 1.79181e+06 0.00192341 6.02e+05 0.00192
254 14011 1.79181e+06 0.00480852 6.02e+05 0.00481
255 14088 1.78736e+06 0.00120213 6.02e+05 0.0012
256 14089 1.78736e+06 0.00300532 6.02e+05 0.00301
257 14166 1.78466e+06 0.000751331 6.02e+05 0.000751
258 14243 1.7782e+06 0.00187833 6.02e+05 0.00188
259 14244 1.7782e+06 0.00469582 6.02e+05 0.0047
260 14321 1.7739e+06 0.00117395 6.02e+05 0.00117
261 14398 1.76351e+06 0.00293489 6.03e+05 0.00293
262 14399 1.76351e+06 0.00733721 6.03e+05 0.00734
263 14400 1.76351e+06 0.0018343 6.03e+05 0.00183
264 14477 1.76181e+06 0.000458576 6.03e+05 0.000459
265 14554 1.75813e+06 0.00114644 9.59e+06 0.00115
266 14631 1.75767e+06 7.60153e-05 6.03e+05 0.00115
267 14708 1.75389e+06 0.00114644 6.03e+05 0.00115
268 14709 1.75389e+06 0.0028661 6.03e+05 0.00287
269 14786 1.75122e+06 0.000716525 6.03e+05 0.000717
270 14787 1.75122e+06 0.00179131 6.03e+05 0.00179
271 14864 1.7496e+06 0.000447828 6.03e+05 0.000448
272 14941 1.74556e+06 0.00111957 6.03e+05 0.00112
273 15018 1.73557e+06 0.00279892 6.04e+05 0.0028
274 15019 1.73557e+06 0.00699731 6.04e+05 0.007
275 15020 1.73557e+06 0.00174933 6.04e+05 0.00175
276 15097 1.73396e+06 0.000437332 6.04e+05 0.000437
277 15174 1.73032e+06 0.00109333 5.96e+06 0.00109
278 15251 1.72994e+06 9.74068e-05 6.04e+05 0.00273
279 15328 1.72018e+06 0.00273333 6.04e+05 0.00273
280 15329 1.72018e+06 0.00683331 6.04e+05 0.00683
281 15330 1.72018e+06 0.00170833 6.04e+05 0.00171
282 15407 1.71861e+06 0.000427082 6.04e+05 0.000427
283 15484 1.71505e+06 0.00106771 5.75e+06 0.00107
284 15561 1.71468e+06 9.7764e-05 6.04e+05 0.00267
285 15638 1.70511e+06 0.00266926 6.05e+05 0.00267
286 15639 1.70511e+06 0.00667316 6.05e+05 0.00667
287 15640 1.70511e+06 0.00166829 6.05e+05 0.00167
288 15717 1.70359e+06 0.000417072 6.05e+05 0.000417
289 15794 1.69991e+06 0.00104268 1.62e+06 0.00104
290 15871 1.6989e+06 0.00039743 6.05e+05 0.00261
291 15872 1.6989e+06 0.0026067 6.05e+05 0.00261
292 15949 1.6965e+06 0.000651675 6.05e+05 0.000652
293 16026 1.69148e+06 0.00162919 2.99e+07 0.00163
294 16103 1.69076e+06 3.80988e-05 2.73e+06 0.00163
295 16180 1.69029e+06 0.000181819 6.05e+05 0.00163
296 16181 1.69029e+06 0.00162919 6.05e+05 0.00163
297 16258 1.68882e+06 0.000407297 6.05e+05 0.000407
298 16335 1.68514e+06 0.00101824 6.06e+05 0.00102
299 16412 1.67599e+06 0.00254561 8.83e+05 0.00255
300 16489 1.67207e+06 0.00135664 6.06e+05 0.00636
301 16490 1.67207e+06 0.00636402 6.06e+05 0.00636
302 16567 1.6661e+06 0.001591 6.06e+05 0.00159
303 16568 1.6661e+06 0.00397751 6.06e+05 0.00398
304 16645 1.6629e+06 0.000994378 8.86e+06 0.000994
305 16722 1.6625e+06 6.99889e-05 6.06e+05 0.000994
306 16799 1.65915e+06 0.000994378 6.06e+05 0.000994
307 16800 1.65915e+06 0.00248594 6.06e+05 0.00249
308 16877 1.65685e+06 0.000621486 6.06e+05 0.000621
309 16878 1.65685e+06 0.00155372 6.06e+05 0.00155
310 16955 1.65545e+06 0.000388429 6.06e+05 0.000388
311 17032 1.65196e+06 0.000971072 6.07e+05 0.000971
312 17033 1.65196e+06 0.00242768 6.07e+05 0.00243
313 17110 1.64979e+06 0.00060692 6.07e+05 0.000607
314 17187 1.64483e+06 0.0015173 6.07e+05 0.00152
315 17188 1.64483e+06 0.00379325 6.07e+05 0.00379
316 17265 1.64127e+06 0.000948313 6.07e+05 0.000948
317 17266 1.64127e+06 0.00237078 6.07e+05 0.00237
318 17343 1.63914e+06 0.000592695 6.07e+05 0.000593
319 17420 1.63407e+06 0.00148174 6.07e+05 0.00148
320 17421 1.63407e+06 0.00370435 6.07e+05 0.0037
321 17498 1.63066e+06 0.000926087 6.07e+05 0.000926
322 17575 1.62236e+06 0.00231522 6.08e+05 0.00232
323 17576 1.62236e+06 0.00578804 6.08e+05 0.00579
324 17577 1.62236e+06 0.00144701 6.08e+05 0.00145
325 17654 1.62104e+06 0.000361753 6.08e+05 0.000362
326 17731 1.61783e+06 0.000904381 1.2e+06 0.000904
327 17808 1.61613e+06 0.000627361 6.08e+05 0.00226
328 17809 1.61613e+06 0.00226095 6.08e+05 0.00226
329 17886 1.61401e+06 0.000565238 6.08e+05 0.000565
330 17887 1.61401e+06 0.0014131 6.08e+05 0.00141
331 17964 1.61271e+06 0.000353274 6.08e+05 0.000353
332 18041 1.60972e+06 0.000883185 4.15e+06 0.000883
333 18118 1.60939e+06 0.000106805 6.08e+05 0.00221
334 18119 1.60939e+06 0.00220796 6.08e+05 0.00221
335 18196 1.6074e+06 0.000551991 6.08e+05 0.000552
336 18273 1.60256e+06 0.00137998 6.08e+05 0.00138
337 18274 1.60256e+06 0.00344994 6.08e+05 0.00345
338 18351 1.5995e+06 0.000862485 1.51e+06 0.000862
339 18428 1.59851e+06 0.000386172 6.08e+05 0.00216
340 18429 1.59851e+06 0.00215621 6.08e+05 0.00216
341 18506 1.59651e+06 0.000539053 6.08e+05 0.000539
342 18507 1.59651e+06 0.00134763 6.08e+05 0.00135
343 18584 1.59529e+06 0.000336908 6.09e+05 0.000337
344 18661 1.59225e+06 0.000842271 6.1e+05 0.000842
345 18662 1.59225e+06 0.00210568 6.1e+05 0.00211
346 18739 1.59035e+06 0.000526419 6.11e+05 0.000526
347 18816 1.58575e+06 0.00131605 6.12e+05 0.00132
348 18817 1.58575e+06 0.00329012 6.12e+05 0.00329
349 18894 1.58281e+06 0.00082253 1.08e+06 0.000823
350 18971 1.58076e+06 0.000741502 6.13e+05 0.00206
351 18972 1.58076e+06 0.00205633 6.13e+05 0.00206
352 19049 1.57882e+06 0.000514081 6.15e+05 0.000514
353 19050 1.57882e+06 0.0012852 6.15e+05 0.00129
354 19127 1.57762e+06 0.000321301 6.17e+05 0.000321
355 19204 1.57493e+06 0.000803252 4.75e+06 0.000803
356 19281 1.57462e+06 9.11005e-05 6.19e+05 0.00201
357 19358 1.56738e+06 0.00200813 7.4e+05 0.00201
358 19435 1.56214e+06 0.00174788 6.2e+05 0.00502
359 19436 1.56214e+06 0.00502033 6.2e+05 0.00502
360 19513 1.55738e+06 0.00125508 6.27e+05 0.00126
361 19514 1.55738e+06 0.0031377 6.27e+05 0.00314
362 19591 1.55447e+06 0.000784426 6.3e+05 0.000784
363 19668 1.54777e+06 0.00196106 1.26e+07 0.00196
364 19745 1.54739e+06 4.85293e-05 8.57e+05 0.0049
365 19822 1.54392e+06 0.00119144 6.32e+05 0.0049
366 19823 1.54392e+06 0.00490266 6.32e+05 0.0049
367 19900 1.53929e+06 0.00122567 6.38e+05 0.00123
368 19901 1.53929e+06 0.00306416 6.38e+05 0.00306
369 19978 1.53674e+06 0.000766041 5.46e+06 0.000766
370 20055 1.53645e+06 7.75969e-05 6.41e+05 0.00192
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 2.000000e+04.
################################### Error Error
hello
sorry , I cannot help regarding fsolve (I don't use the Optimization Toolbox)
Please who can help me then with fsolve prematurely. Actually, I posted a different question with that, but it appears no has viewd that yet. I will post a new one again.
Change
options = optimset('Display', 'iter', 'MaxFunEvals', 20000, 'MaxIter', 20000, 'TolFun', 1e-10, 'TolX', 1e-10);
to increae the MaxFunEvals and MaxIter options
So I increaased both the MaxFunEvals and MaxIter options to 1e+7, but still the same problem, it stopped prematurely. Below is the error. Thanks for the response.
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 1.000000e+07.
Elapsed time is 3086.498409 seconds.
Increase them more -- 10 million was not enough.
Or look at your output to get an idea of how close you are to a solution, and modify your tolerances so that you would accept something it came up with.
The portion of the output you posted does not, however, appear to be coming up with any good solution.
Question: does your code involve any random number generation? If it does, it might not converge.
Please below is the output of the code. I do not have any random number generation in my code. Also, how do I check the output and know how close I am to a solution and how can I modify the tolerance. Actually, it takes long to run the code. Please can you explain things better for me. Thanks.
157944 9994777 610092 1.23862e-08 9.07e+05 3.46e-08
157945 9994854 610092 3.45889e-08 4.86e+06 3.46e-08
157946 9994931 610092 1.23862e-08 9.07e+05 3.46e-08
157947 9995008 610092 3.45889e-08 4.86e+06 3.46e-08
157948 9995085 610092 1.23862e-08 9.07e+05 3.46e-08
157949 9995162 610092 3.45889e-08 4.86e+06 3.46e-08
157950 9995239 610092 1.23862e-08 9.07e+05 3.46e-08
157951 9995316 610092 3.45889e-08 4.86e+06 3.46e-08
157952 9995393 610092 1.23862e-08 9.07e+05 3.46e-08
157953 9995470 610092 3.45889e-08 4.86e+06 3.46e-08
157954 9995547 610092 1.23862e-08 9.07e+05 3.46e-08
157955 9995624 610092 3.45889e-08 4.87e+06 3.46e-08
157956 9995701 610092 1.23862e-08 9.07e+05 3.46e-08
157957 9995778 610092 3.45889e-08 4.87e+06 3.46e-08
157958 9995855 610092 1.23863e-08 9.07e+05 3.46e-08
157959 9995932 610092 3.45889e-08 4.87e+06 3.46e-08
157960 9996009 610091 1.23863e-08 9.07e+05 3.46e-08
157961 9996086 610091 3.45889e-08 4.87e+06 3.46e-08
157962 9996163 610091 1.23863e-08 9.07e+05 3.46e-08
157963 9996240 610091 3.45889e-08 4.87e+06 3.46e-08
157964 9996317 610091 1.23863e-08 9.07e+05 3.46e-08
157965 9996394 610091 3.45889e-08 4.87e+06 3.46e-08
157966 9996471 610091 1.23863e-08 9.07e+05 3.46e-08
157967 9996548 610091 3.45889e-08 4.87e+06 3.46e-08
157968 9996625 610091 1.23863e-08 9.07e+05 3.46e-08
157969 9996702 610091 3.45889e-08 4.87e+06 3.46e-08
157970 9996779 610091 1.23863e-08 9.07e+05 3.46e-08
157971 9996856 610091 3.45889e-08 4.87e+06 3.46e-08
157972 9996933 610091 1.23863e-08 9.07e+05 3.46e-08
157973 9997010 610091 3.45889e-08 4.87e+06 3.46e-08
157974 9997087 610091 1.23863e-08 9.07e+05 3.46e-08
157975 9997164 610091 3.45889e-08 4.87e+06 3.46e-08
157976 9997241 610091 1.23863e-08 9.07e+05 3.46e-08
157977 9997318 610091 3.45889e-08 4.87e+06 3.46e-08
157978 9997395 610091 1.23863e-08 9.07e+05 3.46e-08
157979 9997472 610091 3.45889e-08 4.87e+06 3.46e-08
157980 9997549 610091 1.23863e-08 9.07e+05 3.46e-08
157981 9997626 610091 3.45889e-08 4.87e+06 3.46e-08
157982 9997703 610091 1.23863e-08 9.07e+05 3.46e-08
157983 9997780 610091 3.45889e-08 4.87e+06 3.46e-08
157984 9997857 610091 1.23863e-08 9.07e+05 3.46e-08
157985 9997934 610091 3.45889e-08 4.87e+06 3.46e-08
157986 9998011 610090 1.23863e-08 9.07e+05 3.46e-08
157987 9998088 610090 3.45889e-08 4.87e+06 3.46e-08
157988 9998165 610090 1.23863e-08 9.07e+05 3.46e-08
157989 9998242 610090 3.45889e-08 4.87e+06 3.46e-08
157990 9998319 610090 1.23863e-08 9.07e+05 3.46e-08
157991 9998396 610090 3.45889e-08 4.87e+06 3.46e-08
157992 9998473 610090 1.23863e-08 9.07e+05 3.46e-08
157993 9998550 610090 3.45889e-08 4.87e+06 3.46e-08
157994 9998627 610090 1.23863e-08 9.07e+05 3.46e-08
157995 9998704 610090 3.45889e-08 4.87e+06 3.46e-08
157996 9998781 610090 1.23863e-08 9.07e+05 3.46e-08
157997 9998858 610090 3.45889e-08 4.87e+06 3.46e-08
157998 9998935 610090 1.23863e-08 9.07e+05 3.46e-08
157999 9999012 610090 3.45889e-08 4.87e+06 3.46e-08
158000 9999089 610090 1.23863e-08 9.07e+05 3.46e-08
158001 9999166 610090 3.45889e-08 4.87e+06 3.46e-08
158002 9999243 610090 1.23863e-08 9.07e+05 3.46e-08
158003 9999320 610090 3.45889e-08 4.87e+06 3.46e-08
158004 9999397 610090 1.23863e-08 9.07e+05 3.46e-08
158005 9999474 610090 3.45889e-08 4.87e+06 3.46e-08
158006 9999551 610090 1.23863e-08 9.07e+05 3.46e-08
158007 9999628 610090 3.45889e-08 4.87e+06 3.46e-08
158008 9999705 610090 1.23863e-08 9.07e+05 3.46e-08
158009 9999782 610090 3.45889e-08 4.87e+06 3.46e-08
158010 9999859 610090 1.23863e-08 9.07e+05 3.46e-08
158011 9999936 610090 3.45889e-08 4.87e+06 3.46e-08
158012 10000013 610090 1.23863e-08 9.07e+05 3.46e-08
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 1.000000e+07.
Elapsed time is 3086.498409 seconds.
Please can you check my code for me, because I change the MaxFunctionEvaluations and MaxIter to 1e+10, and its still running since 10:30am till now, still running. Please check on my codes for me. thanks. below is the new change.
options = optimset('Display', 'iter', 'MaxFunEvals', 1e+10, 'MaxIter', 1e+10, 'TolFun', 1e-10, 'TolX', 1e-10);
https://www.mathworks.com/help/optim/ug/first-order-optimality-measure.html
Your function appears to evaluate to about 1e-8 but the optimality is about 1e+5. That means that the gradient is about that at its worst. You could set the optimality goal as (say) 1e-7, but be sure to estimate the gradient there to see how much the position can be trusted.
Thanks for the response, please can you explain what gradient is and what optimality is. Also, how can I estimate the gradient there to see how much the position can be trusted.
I am still new to all this. I will appreciate if you can explain it a bit better to me.
Please can you explain what gradient is and what optimality is. Also, how can I estimate the gradient there to see how much the position can be trusted.
I am still new to all this. I will appreciate if you can explain it a bit better to me.
Please can you check my code again for me becuase I have tried changing everything but same problem persist. Or should i change optimset to optimoptions. How can I estimate the gradient there to see how much the position can be trusted. The same error below.
146408 9996997 49932.5 1.27418e-08 1.28e+05 4.28e-08
146409 9997074 49932.5 4.27856e-08 7.88e+05 4.28e-08
146410 9997151 49932.5 1.39206e-08 1.28e+05 4.28e-08
146411 9997228 49932.5 4.27856e-08 5.9e+05 4.28e-08
146412 9997305 49932.5 1.21183e-08 1.28e+05 4.28e-08
146413 9997382 49932.5 3.76537e-08 7.22e+05 4.28e-08
146414 9997459 49932.5 1.33525e-08 1.28e+05 4.28e-08
146415 9997536 49932.5 4.27856e-08 6.85e+05 4.28e-08
146416 9997613 49932.5 1.30205e-08 1.28e+05 4.28e-08
146417 9997690 49932.5 4.27856e-08 7.41e+05 4.28e-08
146418 9997767 49932.5 1.3518e-08 1.28e+05 4.28e-08
146419 9997844 49932.5 4.27856e-08 6.57e+05 4.28e-08
146420 9997921 49932.5 1.27642e-08 1.28e+05 4.28e-08
146421 9997998 49932.5 4.27856e-08 7.84e+05 4.28e-08
146422 9998075 49932.4 1.38883e-08 1.28e+05 4.28e-08
146423 9998152 49932.4 4.27856e-08 5.95e+05 4.28e-08
146424 9998229 49932.4 1.21706e-08 1.28e+05 4.28e-08
146425 9998306 49932.4 3.81037e-08 7.29e+05 4.28e-08
146426 9998383 49932.4 1.34153e-08 1.28e+05 4.28e-08
146427 9998460 49932.4 4.27856e-08 6.75e+05 4.28e-08
146428 9998537 49932.4 1.29234e-08 1.28e+05 4.28e-08
146429 9998614 49932.4 4.27856e-08 7.57e+05 4.28e-08
146430 9998691 49932.4 1.36593e-08 1.28e+05 4.28e-08
146431 9998768 49932.4 4.27856e-08 6.34e+05 4.28e-08
146432 9998845 49932.4 1.25405e-08 1.28e+05 4.28e-08
146433 9998922 49932.4 4.16371e-08 7.86e+05 4.28e-08
146434 9998999 49932.4 1.39004e-08 1.28e+05 4.28e-08
146435 9999076 49932.4 4.27856e-08 5.93e+05 4.28e-08
146436 9999153 49932.4 1.21501e-08 1.28e+05 4.28e-08
146437 9999230 49932.4 3.79206e-08 7.27e+05 4.28e-08
146438 9999307 49932.4 1.33885e-08 1.28e+05 4.28e-08
146439 9999384 49932.4 4.27856e-08 6.79e+05 4.28e-08
146440 9999461 49932.3 1.29642e-08 1.28e+05 4.28e-08
146441 9999538 49932.3 4.27856e-08 7.51e+05 4.28e-08
146442 9999615 49932.3 1.35994e-08 1.28e+05 4.28e-08
146443 9999692 49932.3 4.27856e-08 6.44e+05 4.28e-08
146444 9999769 49932.3 1.2635e-08 1.28e+05 4.28e-08
146445 9999846 49932.3 4.2642e-08 8.02e+05 4.28e-08
146446 9999923 49932.3 1.40328e-08 1.28e+05 4.28e-08
146447 10000000 49932.3 4.27856e-08 5.71e+05 4.28e-08
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 1.000000e+07.
Elapsed time is 3088.028309 seconds.
>>
can you explain what gradient is
Given a function F with N inputs, then you can construct
This is the Gradient function.
Then for any particular set of inputs, you can evaluate the gradient function G at to get the list of numeric derivatives, g, at that location.
You can then take the 2-norm of g, which would be sqrt(sum(g(:).^2)) (but just use norm(), it is shorter). This gives you an approximate idea of how "big" the norm components are -- the length of a vector with those components. This is what fsolve() calls the "first level optimality" .
fsolve() does not, however, have access to the actual function in order to be able to take derivatives. Instead, it evaluates the function N times with slightly different inputs, and uses that to estimate the "slope" along each direction. Does a change of 1e-5 in the 4th variable result in a much larger function value but a change of 1e-5 in the 2nd variable hardly changes anything? Given a particular point, you can estimate how much the function curves with respect to each of the variables -- and that estimate is the numeric gradient.
So, at the end of the search, when fsolve() has returned a list of values, X, then evaluate
Fx = reshape(Gesolve(X), 1, []);
Nx = length(X);
g = zeros(Nx, length(Fx));
for K = 1 : Nx
testX = X; testX(K) = testX(K) + 1e-5;
g(K, :) = GEsolve(testX);
end
differences = abs(g - Fx);
reldifferences = differences ./Fx;
was0 = Fx == 0;
if any(was0)
reldifferences(:,was0) = differences(:,was0);
fprintf('Warning: absolute difference used for variable(s) #%s\n', mat2str(find(was0)));
end
maxreldifference = max(reldifferences(:))
at this point, reldifferences is a measure of relative differences of the nearby points -- relative so that a change of 1/10 in a large number is not as significant as a change of 1/10 in a small number. maxreldifference is the worst case relative difference over the whole system. If it is "small" then the end location is pretty good; if it is "large" then you should examine the entire reldifferences matrix to see which variable (row number) and which equation (column number) is giving trouble.
Tested code to go at the end of your current code:
X = x;
Fx = reshape(GEsolve(X), 1, []);
Nx = length(X);
g = zeros(Nx, length(Fx));
for K = 1 : Nx
testX = X; testX(K) = testX(K) + 1e-5;
g(K, :) = reshape(GEsolve(testX), 1, []);
end
differences = abs(g - Fx);
reldifferences = differences ./Fx;
was0 = Fx == 0;
if any(was0)
reldifferences(:,was0) = differences(:,was0);
fprintf('Warning: absolute difference used for variable(s) #%s\n', mat2str(find(was0)));
end
maxreldifference = max(abs(reldifferences(:)))
After 1e6 iterations, maxreldifference was 1.13662450079165 which is Not Good At All.
It turned out that the 1e-5 that I was using to move by was a significant change for one particular variable. I am working on figuring out better values and better calculations.
Thanks for response, I will work on that you have said to see if the codes get a solution. Please have you come up with better values and better calculations. But I am trying what you have given so far.
I got significant movement of variables between 1e6 function calls and 1e7 function calls even though norm of the estimated gradients did not look too bad at 1e6. norm() of the result of calling the function on the last position (optimality) decreased from 800's to 200's.
I am running 1e8 now (oh darn, just noticed that I did not increase maximum iterations to match.)
You are working with 76 variables and a notable number of outputs (will need to verify the number later.) There might be clever approaches, but I think you might possibly need 3^76 tests to verify that you are at minima.
Thanks for the response, please did you arrive at anything for me. Also, what is 3^76 tests to verify that you are at minima??
I am still new to all this, so sorry if I am asking lot of questions.
Tested code to go at the end of your current code:
Does that mean same m file. but the tested code will be at the bottom of it. Thanks.

Iniciar sesión para comentar.

 Respuesta aceptada

Consolidated code, as you are having difficulty understanding me:
I do not recommend running this with maximum function evaluations set to 1e8, which is what I am currently running on my system. The display of all those iterations slows the program down a lot.
1e7 function evaluations took about half an hour on my system. I estimate it would take closer to an hour on your system, based upon the times you reported earlier.

52 comentarios

You have a system with 76 variables. Imagine that you found a local minima. At a local minima, the gradient would be 0 in all directions. But you can only due a numeric estimate of the gradient: you cannot access the symbolic expression of the gradient or calculate the jacobian (the set of partial differentials of each variable with respect to each other variable.)
How would you verify numerically that you really are at the minima ?
maybe_min = true;
Fx = reshape(GEsolve(x), 1, []);
for K = 1 : numel(x)
testpoint = x;
testpoint(K) = testpoint(K) + delta;
testvalue = reshape(GEsolve(x), 1, []);
if any(testvalue < Fx)
maybe_min = false;
break
end
end
if maybe_min
fprintf('Survived first test\n');
else
fprintf('No, changing variable #%d lowers value\n', K);
end
However.. this only tests each variable independently, and does not test the possibility that there is a minima if two variables change together. It also does not test subtracting delta.
I am not sure at the moment how many tests you need to do in order to check out "three variables working together", "four variables working together", and so on -- I am not sure if there are mathematical shortcuts you can take that do not require testing each possibility, like "x1 + delta, x2 + delta, x3 - delta, x4, x5 - delta, x6 + delta" and so on. That is three possibilities for each position: xn, xn+delta, xn-delta . Three possibilities in each of 76 positions might possibly require testing 3 to the power of 76 different combinations... unless there turns out to be a smarter way to do the testing.
My test with ie8 iterations showed that some of the variables changed value by about +/- 0.68, but the norm() of the GEsolve(x) values changed only from about 223 (1e7 iterations) to 221 (1e8 iterations).
Each iteration appeared to be getting more optimal -- but progress was slow.
Thanks much Walter for all the these comments and the explanation. Let me incorporte all these and finally update you on what I get
Please is delta the same as 1e-10, as in the test code
delta is theory, 1e-10 is abitrary specific value for delta, that might have to be adjusted.
Sounds good, thanks I used that already. Please fsolve is still stopping prematturely, below is what I got.
146432 9998845 49932.4 1.25405e-08 1.28e+05 4.28e-08
146433 9998922 49932.4 4.16371e-08 7.86e+05 4.28e-08
146434 9998999 49932.4 1.39004e-08 1.28e+05 4.28e-08
146435 9999076 49932.4 4.27856e-08 5.93e+05 4.28e-08
146436 9999153 49932.4 1.21501e-08 1.28e+05 4.28e-08
146437 9999230 49932.4 3.79206e-08 7.27e+05 4.28e-08
146438 9999307 49932.4 1.33885e-08 1.28e+05 4.28e-08
146439 9999384 49932.4 4.27856e-08 6.79e+05 4.28e-08
146440 9999461 49932.3 1.29642e-08 1.28e+05 4.28e-08
146441 9999538 49932.3 4.27856e-08 7.51e+05 4.28e-08
146442 9999615 49932.3 1.35994e-08 1.28e+05 4.28e-08
146443 9999692 49932.3 4.27856e-08 6.44e+05 4.28e-08
146444 9999769 49932.3 1.2635e-08 1.28e+05 4.28e-08
146445 9999846 49932.3 4.2642e-08 8.02e+05 4.28e-08
146446 9999923 49932.3 1.40328e-08 1.28e+05 4.28e-08
146447 10000000 49932.3 4.27856e-08 5.71e+05 4.28e-08
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 1.000000e+07.
maxreldifference =
0.0102
Elapsed time is 2875.718426 seconds.
There is nothing you can realistically do about that as long as you continue to use fsolve() .
I ran it to 1E8 calls but it did not do much better than 1E7 calls. There is no reason to expect that 1E9 calls would allow it to converge.
You can do a significantly better job in about 3 seconds if you change your approach.
Your GEsolve() function is emitting a 4 x 19 array of values, each of which would ideally become 0 if you were to find a solution to all of the equations together. Because the targets are all 0, you can examine
sum((GEsolve(x) - 0).^2, [], 'all')
which is
sum(GEsolve(x).^2, [], 'all')
This is a Sum Of Squared Error (SSE) value. If all of the GEsolve() results were 0, then the sum of squares would be 0, and the further away the SSE is from 0, the further away you are (in some sense) from the solution.
So, SSE is a "proxy" for how "good" the solution is. And that means that instead of using fsolve() to try to solve all of the equations simultaneously, you can instead minimize the SSE, using a minimizer instead of a zero-finder.
... and when you do that, you get a much better solution in a small number of seconds.
You cannot get the error down to 0. It is possible that there is no perfect solution. But in 30 iterations you can get maxreldifference down to 1e-9, which is a factor of 10^7 better than before.
% ***********************************
% JOB MARKET PAPER 2019-2021
% AUTHOR: Celestine Siameh
% TOPIC: Brexit and Global Value Chain Beyond the UK and the EU
% GOAL: Model Solving and Calibration
% Main Script Program
%
% ***********************************
tic;
global alpha gama sigma rho tau Ais Li beta IOcoef IOmat_cs_c IOmat_cs Nsec Ncoun
%******************************************
% Define country-sector inputs %
%******************************************
Nsec = 2;
Ncoun = 4;
%******************************************
% Define parameters %
%******************************************
sigma = 5*ones(Nsec,1); %elasticity of substitution for households
rho = 5*ones(Nsec,1); %elasticity of substitution for firm
beta = 0.6*ones(Nsec*Ncoun,1); %value-added share
Li = 1*ones(Ncoun,1); %labor (supply) endowment
Ais = 1*ones(Nsec*Ncoun,1); %TFP
tau = 1.5*ones(Nsec*Ncoun,Ncoun); %tariff
alpha = 0.6*ones(Nsec*Ncoun,Ncoun); %sector share of expenditure for final demand
gama = 0.4*ones(Nsec*Ncoun,Ncoun); %sector share of expenditure for intermediate demand
IOcoef = importdata('IOcoef.txt');
% reformat IOcoef to (NS,S) instead of the initial (NS,NS)
IOmat_cs_c = nan(Ncoun*Nsec,Ncoun); %cs-s
for t = 1:1:Ncoun
IOmat_cs_c(:,t) = sum(IOcoef(:,((t-1)*Nsec+1):Nsec*t),2); %cs-s
end
IOmat_cs = sum(IOmat_cs_c,2); %change IOcoef to (NS,1) instead of (NS,S)
% reformat IOcoef to (NS,S) instead of the initial (NS,NS)
IOmat_cs_s = nan(Ncoun*Nsec,Nsec); %cs-s
for u = 1:1:Nsec
IOmat_cs_s(:,u) = sum(IOcoef(:,((u-1)*Ncoun+1):Ncoun*u),2); %cs-s
end
%******************************************
% minimize residue of non-linear equations (fmincon) %
%******************************************
options = optimoptions('fmincon', 'Display', 'iter', 'TolFun', 1e-15, 'TolX', 1e-15);
% initial guess vakues for x matrix
x0 = 0.5.*ones(4,19);
residue = @(x) sum(reshape(GEsolve(x).^2, 1, []));
A = []; Aeq = []; b = []; beq = []; lb = []; ub = []; nonlcon = [];
[x, fval] = fmincon(residue, x0, A, b, Aeq, beq, lb, ub, nonlcon, options);
display(fval)
% solution of the model in terms of x
wi = x(:,1); %c-1
mij = x(:,2:Ncoun*Nsec+1); %c-cs
fij = x(:,Ncoun*Nsec+2:end-Nsec); %c-cs
pis = x(:,end-Nsec+1:end); %c-s
%******************************************
% Examine the model solution %
%******************************************
X = x;
Fx = reshape(GEsolve(X), 1, []);
Nx = numel(X);
g = zeros(Nx, length(Fx));
for K = 1 : Nx
testX = X; testX(K) = testX(K) + 1e-10;
g(K, :) = reshape(GEsolve(testX), 1, []);
end
differences = abs(g - Fx);
reldifferences = differences ./Fx;
was0 = Fx == 0;
if any(was0)
reldifferences(:,was0) = differences(:,was0);
fprintf('Warning: absolute difference used for variable(s) #%s\n', mat2str(find(was0)));
end
maxreldifference = max(abs(reldifferences(:))) %#ok<NOPTS>
Please, can I take this as an answer and use it like that.
Becuase you said if the maxreldifference is small, then the end location is pretty good but if is large then i should examine the reldifference. Currently, I have maxreldifference as 0,0102, which is small and less than one. Also, I checked reldifference and it appears there is more zeros than negative values. Or maybe use a better solver apart from fsolve, if so which other solver will you suggest I use.
Thanks,
Celestine
It doesn't matter to me if you submit the solution using fsolve() using only 1 iteration, or using 1e5 or 1e10 iterations. It is not my course marks.
However, if someone is requiring that you use fsolve() instead of the very much faster fmincon() approach, then they probably did not prohibit you from first using fmincon() to "estimate" a starting position that you then use with fsolve()
Actually, this is my dissertation and not an assignment. I later have to replicate what I have solved with Nsec = 12 and Ncoun = 34, so that will be more challenging, that is why I want to use the best approach with a better solution as much as possible. I believe that will help me in solving for more sectors of 12 and more countries of 34.
Also, I thought fmincon was for minimization of the actual optimization problem. But in my case I have already solved for the main optimization problem manually to get quations for mij,fij, pis, and wi. So now I am solving those optimal equations simultaneously using numerical methods to get the implied optimal values for the 4 variables.
This then means for now if I use fmincon, then I am using it to minimize the SSE of the optimal equations that I have already solved. Please which is which.
Thannks.
This is pretty straight forward and is 1e-9, which is better than fsolve that gave 0.0102 maxreldifference.
Please is this approach similar to fixed point iteration.
>> GEmod_fmincon
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 77 5.828844e+07 0.000e+00 4.360e+06
1 158 1.836046e+01 0.000e+00 3.804e+00 8.718e+00
2 237 9.265246e+00 0.000e+00 3.144e+00 1.779e+00
3 321 8.787271e+00 0.000e+00 4.811e+00 4.447e-01
4 400 8.323048e+00 0.000e+00 4.926e+00 2.224e-01
5 481 8.265835e+00 0.000e+00 2.154e+01 4.447e-01
6 560 8.052429e+00 0.000e+00 1.396e+01 2.224e-01
7 642 7.523471e+00 0.000e+00 1.797e+01 2.224e-01
8 722 7.457950e+00 0.000e+00 1.266e+01 5.559e-02
9 801 7.276044e+00 0.000e+00 8.522e+00 1.859e-01
10 884 6.882392e+00 0.000e+00 3.974e+00 9.296e-02
11 963 6.845449e+00 0.000e+00 2.982e+00 9.296e-02
12 1047 6.780110e+00 0.000e+00 1.228e+00 2.324e-02
13 1131 6.764439e+00 0.000e+00 7.038e-01 2.034e-02
14 1209 6.763336e+00 0.000e+00 2.623e+00 4.067e-02
15 1290 6.735800e+00 0.000e+00 1.661e+00 8.134e-02
16 1370 6.732261e+00 0.000e+00 2.421e+00 3.937e-02
17 1450 6.727390e+00 0.000e+00 1.902e+00 2.086e-02
18 1530 6.709908e+00 0.000e+00 1.015e+00 4.616e-02
19 1607 6.702313e+00 0.000e+00 3.860e-01 1.659e-02
20 1684 6.701287e+00 0.000e+00 4.171e-01 1.661e-02
21 1761 6.700436e+00 0.000e+00 3.238e-02 3.073e-03
22 1838 6.700412e+00 0.000e+00 1.020e-02 1.747e-03
23 1915 6.700409e+00 0.000e+00 2.379e-03 9.450e-04
24 1992 6.700409e+00 0.000e+00 6.293e-04 2.811e-05
25 2069 6.700409e+00 0.000e+00 3.719e-05 6.342e-06
26 2146 6.700409e+00 0.000e+00 5.901e-06 6.853e-07
27 2223 6.700409e+00 0.000e+00 5.960e-07 1.255e-07
28 2300 6.700409e+00 0.000e+00 2.980e-07 6.863e-08
29 2390 6.700409e+00 0.000e+00 2.980e-07 4.871e-11
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
fval =
6.7004
maxreldifference =
1.1324e-09
Elapsed time is 0.808661 seconds.
>>
So now I am solving those optimal equations simultaneously using numerical methods to get the implied optimal values for the 4 variables.
I am not sure of that. You have 76 equations in 76 variables. The 76 variables are arranged in 4 x 19 pattern that I do not know the significance of at the moment... but is 76 variables you are trying to solve for, not 4 variables.
Thanks for the response. Yes, I have 76 equations because equation 1 estimate 32 variables, equation 2 estimate 32 variables, equation 3 estimate8 variables and equation 4 estimate 4 variables; all add up to 76 variables. This is becuase is multi-layered, that is country - sector variables.
I think since maxreldiffference is 1e-9 less than the tolerance of 1e-8, I will stick to the fmincon, as that is better than the 0.0102.
Also, how about using this instead:
maxreldifference = max(max(abs(reldifferences(:)))) %#ok<NOPTS>
I just realized you used a tol of 1e-15 which is less than 1e-9 instead. But I tried with tol of 1e-8 and it was same maxreldifference of 1e-9.
options = optimoptions('fmincon', 'Display', 'iter', 'TolFun', 1e-15, 'TolX', 1e-15);
How about "Lsqnonlin", can I please try with that?? Is it good for this particular problem??
Please what do you think.
On my system, when I used 1e-15 as the tolerance, I got 30 iterations out instead of the 28 I got with 1e-8 . The final stepsize is about 1e-15 when I used 1e-15 as the tolerance.
maxreldifference = max(max(abs(reldifferences(:)))) %#ok<NOPTS>
reldifferences is a 2D array. reldifferences(:) is a column vector. abs() of it would be a column vector the same size. max() of a column vector is a scalar. max() applied to a scalar is the same scalar.
Therefore, using max(max(something(:))) is not necessary.
If you wanted to use max(max()) for some reason you would use
maxreldifference = max(max(abs(reldifferences))) %#ok<NOPTS>
the abs() of a 2D array would be a 2D array, max() of a 2D array would be a row vector, max() of a row vector would be a scalar. But you have used an extra max() call compared to using a single max() together with (:) . The (:) operator is nearly the fastest operator there is when it is applied to a real-valued array, so it is more efficient to use (:) and a single max() when you want to find the overall maximum of something with 2 or more dimensions.
Lsqnonlin produced the same results as the fmincon. I think i will go with both since the answer is the same, and then I will replicate with more countries, more sectors, and the actual data set. I will use either of them. But lsqnonlin was 26 iterations and more faster than fmincon, though both are still faster.
Thanks so much for all the help Walter. I really appreciate it. I will let you know what happens when I replicate with more countries and the actual data sets.
Therefore, using max(max(something(:))) is not necessary.
If you wanted to use max(max()) for some reason you would use
I declined using max max. Thanks for the explantion that.
with lsqnonlin() you would not need to construct the residue function; you should be able to lsqnonlin(@GEsolve, x0) .
Yes, it is exactly what i did, and it produce the same results as fmincon. It is very fast. I hope this looks better than the fsolve.
>> GE_lsqnonlin
Norm of First-order
Iteration Func-count f(x) step optimality
0 77 5.82884e+07 2.18e+06
1 154 5.82884e+07 10 2.18e+06
2 231 8.60124e+06 2.76971 6.22e+06
3 308 8.60124e+06 5 6.22e+06
4 385 7.3719e+06 1.25 7.43e+06
5 462 3.81641e+06 1.25 2.41e+06
6 539 258630 2.2593 5.84e+05
7 616 6.82996 0.729267 152
8 693 6.82996 0.223128 152
9 770 6.71841 0.0557821 0.632
10 847 6.71841 0.098441 0.632
11 924 6.70922 0.0246102 0.479
12 1001 6.70846 0.0246102 0.602
13 1078 6.70165 0.00615256 0.163
14 1155 6.70122 0.0123051 0.173
15 1232 6.70042 0.00307628 0.00693
16 1309 6.70042 0.00307628 0.00834
17 1386 6.70042 0.00237098 0.00834
18 1463 6.70041 0.000592744 0.00824
19 1540 6.70041 0.000592744 0.00839
20 1617 6.70041 0.000148186 0.000254
21 1694 6.70041 0.000148186 9.69e-05
22 1771 6.70041 3.6191e-05 9.69e-05
23 1848 6.70041 9.04774e-06 8.81e-05
24 1925 6.70041 9.04774e-06 9.27e-05
25 2002 6.70041 3.92251e-06 9.27e-05
26 2079 6.70041 9.80627e-07 3.51e-05
Local minimum possible.
lsqnonlin stopped because the final change in the sum of squares relative to
its initial value is less than the value of the function tolerance.
<stopping criteria details>
maxreldifference =
1.1324e-09
Survived first test
Elapsed time is 0.661080 seconds.
I was having another look at the problem, and I noticed a potential issue.
tol = 1e-8; %Tolerance, use to keep certain variables away from zero
wi = max(wi, tol);
mij = max(mij, tol);
fij = max(fij, tol);
pis = max(pis, tol);
The idea was probably to prevent a division by 0. But the particular way you implemented that means that if negative values are proposed for those variables, that tol will be used instead. And that turns out to be a live issue, as wi, mij, and fij (but not pis) are all negative in the values proposed by fmincon() .
Do any of the inputs have range restrictions? Such as non-negative? If so then that can be implemented by using the ub and lb parameters of fmincon()
If we assume non-negative then we can get a bit better than above:
tol = 1e-8;
GGG=@(x) sum(GEsolve(reshape(x,4,19)).^2,'all')
opts = optimoptions(@fmincon,'MaxFunctionEvaluations', 1e5, 'MaxIterations', 1e5);
x0 = rand(4,19);
[x, fval ] = fmincon(GGG, x0, [], [], [], [], tol*ones(4,19), inf(4,19), [], opts)
A lot of the values do not change much from tol, and the rows are suspiciously equal for a number of them.
The values being near tol implies that the algorithm was finding that heading towards the lower bound was lowering the values -- which suggests that using a smaller tolerance might be useful. If you use a lower tolerance remember to change it inside GEsolve as well.
It looks like "unfortunate" rand values can lead to the fmincon running into problems.
One decent set of values with tol 1e-15
x0 = [9.61991140739188e-10 9.51075817873712e-10 2.58631189724177e-11 1.83505693424942e-13 4.2109785339108e-07 3.84887490805534e-10 5.83020321320705e-09 3.73614699493173e-11 8.59071442348517e-11 1.92359757702064e-06 1.54524845345846e-05 9.6263397726183e-09 3.90292871456847e-08 0.000132316100436112 9.54718287629187e-06 3.77932270176483e-07 7.9916863357593e-08 0.229323359855012 0.168046263517247;4.13269586466152e-11 1.01394029347174e-09 2.61463245067226e-11 1.83505487732867e-13 4.2099860540043e-07 4.0474867771436e-10 5.83366589297193e-09 3.73738000420885e-11 8.59074605859489e-11 4.93880228211785e-05 1.54524822786235e-05 9.63060168090734e-09 3.90399550055325e-08 0.000151262599841859 9.54738084693423e-06 3.77932642065121e-07 8.01155582032694e-08 0.138830539616554 0.210984615943929;8.74562621914925e-08 9.74448393047576e-10 2.59824724525824e-11 1.83505690102757e-13 4.21237168141821e-07 4.1740344771469e-10 5.82888228319421e-09 3.73569389978658e-11 8.59075041909588e-11 1.35116517720906e-05 1.54546889629288e-05 9.4293894748743e-09 3.9046324051788e-08 0.000151145421242768 9.5471651178027e-06 3.77932615718285e-07 7.97196302278328e-08 0.0980110248544734 0.151336162408903;5.9902017109498e-05 9.4988454677192e-10 2.5963480258741e-11 1.83505486770266e-13 4.20946595967389e-07 3.86855273191292e-10 5.86070121655479e-09 3.73728129324199e-11 8.59073532818703e-11 4.10313377768185e-05 1.54527880932045e-05 9.54246641720074e-09 3.90293488705882e-08 0.000151232607719937 9.54783765593213e-06 3.77932819112172e-07 8.08701940366836e-08 0.401208236443036 0.161995008338097]
though at the moment I am not sure the residue is much better than searching with the 1e-8 tolerance. The x values in the last two columns are significantly different than with the 1e-8 tolerance though... which is not good news for any hopes of claiming that the values have inherent meaning (as opposed to their relationship potentially being important.)
Please recheck to see whether you should have lower bounds. You have some fractional powers, so you probably need to make sure that the values being taken to a fraction are never negative.
Yes actually, that is the problem i notice but i thought is because of the values that I am using that is why I am getting the negative values. Please all variables (wi, mij, fij, pis) are non-zero and non-negative. The variables are prices and quantities and I simply cannot have negative prices and quantities. Can we use actual values instead of rand values but if not that is ok. Please 1e-15 tol the best to use. Thanks.
The fmincon version I posted when I asked about bounds will prevent those values from going negative or less than the tol version you configure.
Note: if you change tol in the code that steps up the fmincon() call, then you should also change tol inside GEsolve()
The fval you get back from the fmincon() call is a sum-of-squared errors value, the square of norm() of the GEsolve values.
I tried using the above method. But the maxreldifference was quite larger than the tolerance. Please can you check that for me. But all variables solved values were non-zero and non-negative, which is good. But I thought to reach a better convergence maxreldifference must be less than tol. I used tol of 1e-8 for the below results same as what you have above. But 0.0330 maxreldifference is greater than tol. Also, can I use actual values instead of random values, since that changes the results anytime I run. Thanks.
>> fminicon_WR_N
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 77 1.459275e+13 0.000e+00 1.216e+15
1 155 1.609486e+11 0.000e+00 9.742e+12 7.482e-01
2 232 1.560023e+09 0.000e+00 4.863e+10 7.808e-01
3 311 7.554911e+08 0.000e+00 1.463e+10 1.532e-01
4 388 1.425347e+08 0.000e+00 1.458e+09 2.277e-01
5 466 1.041162e+08 0.000e+00 1.132e+09 2.252e-01
6 544 6.918526e+07 0.000e+00 1.778e+08 1.049e-01
7 623 6.034262e+07 0.000e+00 7.887e+07 6.099e-02
8 704 5.918464e+07 0.000e+00 5.686e+07 2.909e-02
9 781 5.754830e+07 0.000e+00 6.528e+07 7.052e-02
10 858 5.490172e+07 0.000e+00 6.693e+07 1.463e-01
11 937 5.332489e+07 0.000e+00 8.188e+07 6.086e-02
12 1015 5.226127e+07 0.000e+00 9.575e+07 6.383e-02
13 1092 5.100724e+07 0.000e+00 7.552e+07 6.269e-02
14 1174 5.047121e+07 0.000e+00 5.401e+07 6.235e-02
15 1251 4.979226e+07 0.000e+00 1.102e+08 6.218e-02
16 1332 4.830354e+07 0.000e+00 5.534e+07 5.952e-02
17 1410 4.802808e+07 0.000e+00 7.249e+07 6.313e-02
18 1487 4.643531e+07 0.000e+00 6.872e+07 6.504e-02
19 1565 4.522897e+07 0.000e+00 5.783e+07 6.408e-02
20 1642 4.405486e+07 0.000e+00 9.081e+07 1.473e-01
21 1724 4.145652e+07 0.000e+00 4.344e+07 6.282e-02
22 1803 4.046730e+07 0.000e+00 1.365e+07 3.184e-02
23 1880 3.934240e+07 0.000e+00 3.600e+07 7.373e-02
24 1957 3.648803e+07 0.000e+00 2.275e+07 1.490e-01
25 2036 3.628954e+07 0.000e+00 3.883e+07 6.660e-02
26 2113 3.487641e+07 0.000e+00 4.058e+07 6.955e-02
27 2191 3.484407e+07 0.000e+00 3.169e+07 6.738e-02
28 2268 3.288926e+07 0.000e+00 2.812e+07 6.829e-02
29 2347 3.243766e+07 0.000e+00 9.134e+06 3.384e-02
30 2424 3.146179e+07 0.000e+00 1.932e+07 7.023e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
31 2501 3.045294e+07 0.000e+00 5.906e+07 1.390e-01
32 2584 2.869634e+07 0.000e+00 1.262e+07 6.853e-02
33 2667 2.826267e+07 0.000e+00 1.502e+07 3.435e-02
34 2748 2.750285e+07 0.000e+00 1.857e+07 6.787e-02
35 2829 2.633111e+07 0.000e+00 1.699e+07 1.356e-01
36 2908 2.506823e+07 0.000e+00 1.805e+07 7.281e-02
37 2990 2.503069e+07 0.000e+00 2.247e+07 6.922e-02
38 3071 2.391660e+07 0.000e+00 1.745e+07 6.851e-02
39 3153 2.381412e+07 0.000e+00 3.721e+07 7.148e-02
40 3234 2.262353e+07 0.000e+00 1.343e+07 6.807e-02
41 3316 2.255958e+07 0.000e+00 2.017e+07 7.014e-02
42 3397 2.137720e+07 0.000e+00 8.896e+06 6.719e-02
43 3479 2.128145e+07 0.000e+00 2.538e+07 7.056e-02
44 3560 2.043918e+07 0.000e+00 1.852e+07 6.766e-02
45 3642 2.031172e+07 0.000e+00 1.352e+07 7.232e-02
46 3723 1.921463e+07 0.000e+00 7.712e+06 6.817e-02
47 3807 1.888625e+07 0.000e+00 1.540e+07 5.935e-02
48 3888 1.850212e+07 0.000e+00 1.926e+07 1.109e-01
49 3970 1.739909e+07 0.000e+00 8.708e+06 6.732e-02
50 4052 1.705545e+07 0.000e+00 9.671e+06 5.700e-02
51 4133 1.607068e+07 0.000e+00 1.113e+07 1.032e-01
52 4216 1.574983e+07 0.000e+00 9.411e+06 6.573e-02
53 4297 1.555505e+07 0.000e+00 2.427e+07 1.102e-01
54 4379 1.454182e+07 0.000e+00 6.591e+06 6.917e-02
55 4461 1.434981e+07 0.000e+00 1.198e+07 5.847e-02
56 4542 1.363874e+07 0.000e+00 1.191e+07 1.021e-01
57 4625 1.325009e+07 0.000e+00 7.940e+06 7.019e-02
58 4707 1.299638e+07 0.000e+00 8.830e+06 6.299e-02
59 4788 1.292889e+07 0.000e+00 1.466e+07 1.103e-01
60 4870 1.195294e+07 0.000e+00 2.929e+06 7.408e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
61 4950 1.192481e+07 0.000e+00 4.776e+06 3.497e-02
62 5031 1.164643e+07 0.000e+00 6.929e+06 5.715e-02
63 5109 1.118653e+07 0.000e+00 9.094e+06 9.084e-02
64 5192 1.078163e+07 0.000e+00 5.273e+06 7.188e-02
65 5273 1.071302e+07 0.000e+00 1.298e+07 1.079e-01
66 5351 1.009150e+07 0.000e+00 1.064e+07 7.833e-02
67 5433 1.009105e+07 0.000e+00 1.307e+07 1.531e-01
68 5514 9.121167e+06 0.000e+00 5.957e+06 1.180e-01
69 5592 8.820850e+06 0.000e+00 1.956e+07 2.615e-01
70 5669 1.345433e+06 0.000e+00 4.296e+06 1.452e+00
71 5748 9.131935e+05 0.000e+00 1.065e+06 1.398e+00
72 5825 8.242904e+05 0.000e+00 1.890e+06 1.756e+00
73 5905 5.183752e+05 0.000e+00 1.293e+06 3.119e+00
74 5982 2.021589e+05 0.000e+00 1.000e+06 2.356e+00
75 6059 7.479714e+04 0.000e+00 5.861e+05 6.257e+00
76 6136 3.885071e+04 0.000e+00 3.990e+04 1.172e-01
77 6215 3.267040e+04 0.000e+00 7.396e+04 9.831e+01
78 6292 5.279373e+03 0.000e+00 8.745e+04 5.819e+01
79 6369 4.818446e+03 0.000e+00 1.294e+05 5.249e+00
80 6446 3.209305e+03 0.000e+00 2.175e+04 1.743e+01
81 6523 2.798852e+03 0.000e+00 6.361e+05 1.740e+00
82 6600 1.453541e+03 0.000e+00 1.304e+06 2.554e+01
83 6677 4.835820e+02 0.000e+00 1.032e+06 5.537e+00
84 6754 3.199827e+02 0.000e+00 4.545e+05 3.966e-01
85 6831 1.680318e+02 0.000e+00 2.068e+05 4.531e-01
86 6908 1.217911e+02 0.000e+00 1.865e+05 1.259e-01
87 6985 1.052336e+02 0.000e+00 1.064e+05 9.248e-03
88 7063 1.046529e+02 0.000e+00 6.725e+04 3.552e-02
89 7140 1.002850e+02 0.000e+00 2.348e+05 1.625e-02
90 7219 1.002602e+02 0.000e+00 2.235e+05 9.188e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
91 7297 9.986926e+01 0.000e+00 2.501e+05 3.051e-02
92 7375 9.960446e+01 0.000e+00 1.957e+05 9.914e-03
93 7453 9.943445e+01 0.000e+00 5.830e+04 2.549e-02
94 7530 9.904708e+01 0.000e+00 3.836e+04 3.248e-03
95 7607 9.894197e+01 0.000e+00 3.703e+04 1.004e-03
96 7684 9.855345e+01 0.000e+00 3.448e+04 1.844e-02
97 7761 9.697273e+01 0.000e+00 2.418e+04 9.711e-02
98 7838 9.444413e+01 0.000e+00 4.567e+04 2.600e-01
99 7916 9.426711e+01 0.000e+00 4.631e+04 1.201e-02
100 7994 8.591455e+01 0.000e+00 2.704e+05 1.238e+00
101 8071 8.284064e+01 0.000e+00 1.579e+05 1.697e-01
102 8148 2.319148e+01 0.000e+00 3.348e+06 4.145e+00
103 8226 2.227711e+01 0.000e+00 3.342e+06 3.804e-01
104 8303 2.046630e+01 0.000e+00 1.156e+06 2.168e-01
105 8380 1.963073e+01 0.000e+00 3.513e+06 2.544e-02
106 8457 1.943392e+01 0.000e+00 2.851e+06 5.560e-04
107 8535 1.926162e+01 0.000e+00 7.032e+06 1.946e-02
108 8612 1.706608e+01 0.000e+00 1.843e+06 1.088e-01
109 8689 1.528743e+01 0.000e+00 2.735e+06 1.777e-01
110 8766 1.451675e+01 0.000e+00 2.000e+06 1.343e-01
111 8843 1.382314e+01 0.000e+00 7.729e+06 1.649e-03
112 8921 1.378719e+01 0.000e+00 5.366e+06 2.052e-04
113 8998 1.374757e+01 0.000e+00 5.184e+06 2.910e-02
114 9075 1.357217e+01 0.000e+00 3.807e+06 8.514e-02
115 9152 1.276932e+01 0.000e+00 2.565e+06 1.684e-01
116 9229 1.234751e+01 0.000e+00 1.097e+07 5.297e-04
117 9308 1.230903e+01 0.000e+00 5.971e+06 2.109e-02
118 9385 1.227824e+01 0.000e+00 5.693e+06 2.370e-03
119 9462 1.220026e+01 0.000e+00 5.288e+06 8.286e-03
120 9539 1.199358e+01 0.000e+00 5.568e+06 5.299e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
121 9616 1.172156e+01 0.000e+00 6.801e+06 1.078e-01
122 9693 1.134126e+01 0.000e+00 4.826e+06 2.244e-01
123 9770 1.117337e+01 0.000e+00 2.011e+06 1.088e-01
124 9847 1.113537e+01 0.000e+00 9.433e+05 7.139e-03
125 9924 1.111399e+01 0.000e+00 7.392e+05 7.204e-04
126 10001 1.108846e+01 0.000e+00 1.770e+06 3.754e-03
127 10078 1.099338e+01 0.000e+00 4.667e+06 1.891e-02
128 10155 1.074328e+01 0.000e+00 8.252e+06 5.591e-02
129 10232 1.000363e+01 0.000e+00 1.377e+07 1.941e-01
130 10309 9.167583e+00 0.000e+00 1.384e+07 3.451e-01
131 10386 8.837160e+00 0.000e+00 1.283e+07 8.029e-02
132 10463 8.780073e+00 0.000e+00 1.063e+07 1.147e-01
133 10540 8.176342e+00 0.000e+00 7.320e+06 6.730e-02
134 10617 8.061025e+00 0.000e+00 4.866e+06 2.627e-02
135 10694 8.069284e+00 0.000e+00 3.253e+06 1.538e-02
136 10771 7.692848e+00 0.000e+00 2.044e+06 3.900e-02
137 10848 7.384484e+00 0.000e+00 9.646e+06 2.096e-04
138 10926 7.421595e+00 0.000e+00 2.986e+06 4.889e-03
139 11003 7.407472e+00 0.000e+00 3.373e+06 1.351e-03
140 11080 7.373563e+00 0.000e+00 1.641e+06 1.910e-03
141 11157 7.369005e+00 0.000e+00 1.448e+06 1.379e-03
142 11234 7.338337e+00 0.000e+00 1.054e+06 1.060e-02
143 11311 7.321195e+00 0.000e+00 5.650e+05 1.378e-02
144 11388 7.315964e+00 0.000e+00 2.249e+05 1.792e-02
145 11465 6.689358e+00 0.000e+00 9.644e+05 2.402e-02
146 11542 6.563358e+00 0.000e+00 8.938e+05 3.015e-02
147 11619 6.563722e+00 0.000e+00 5.798e+05 1.234e-02
148 11696 6.560848e+00 0.000e+00 3.860e+05 2.175e-03
149 11773 6.560896e+00 0.000e+00 1.564e+05 5.912e-03
150 11850 6.560798e+00 0.000e+00 5.888e+04 9.485e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
151 11927 6.412016e+00 0.000e+00 2.697e+05 1.283e-02
152 12004 6.404315e+00 0.000e+00 1.704e+05 2.786e-03
153 12082 6.404219e+00 0.000e+00 1.657e+05 3.962e-03
154 12159 6.404146e+00 0.000e+00 1.023e+05 1.355e-03
155 12236 6.403785e+00 0.000e+00 9.495e+04 3.492e-03
156 12313 6.403447e+00 0.000e+00 1.303e+05 3.990e-04
157 12390 6.402352e+00 0.000e+00 1.581e+05 1.666e-03
158 12467 6.396505e+00 0.000e+00 3.902e+05 4.273e-03
159 12544 6.372787e+00 0.000e+00 1.836e+06 1.637e-02
160 12621 6.344857e+00 0.000e+00 2.963e+06 1.708e-02
161 12698 6.280807e+00 0.000e+00 4.070e+06 3.485e-02
162 12775 6.140363e+00 0.000e+00 4.530e+06 7.359e-02
163 12852 5.939170e+00 0.000e+00 4.250e+06 1.051e-01
164 12929 5.754578e+00 0.000e+00 5.832e+06 3.528e-02
165 13006 5.593341e+00 0.000e+00 2.800e+06 1.104e-01
166 13083 5.589055e+00 0.000e+00 3.340e+05 3.730e-02
167 13160 5.590410e+00 0.000e+00 1.705e+05 5.490e-03
168 13237 5.590606e+00 0.000e+00 6.554e+04 4.136e-03
169 13314 5.590724e+00 0.000e+00 3.127e+04 3.443e-04
170 13391 5.590626e+00 0.000e+00 4.979e+04 7.651e-04
171 13468 5.590288e+00 0.000e+00 2.249e+05 2.259e-03
172 13545 5.589559e+00 0.000e+00 3.761e+05 2.134e-03
173 13622 5.586973e+00 0.000e+00 6.913e+05 5.689e-03
174 13699 5.580973e+00 0.000e+00 1.101e+06 1.021e-02
175 13776 5.565184e+00 0.000e+00 1.818e+06 2.211e-02
176 13853 5.527971e+00 0.000e+00 2.680e+06 4.514e-02
177 13930 5.452595e+00 0.000e+00 3.473e+06 8.279e-02
178 14007 5.358840e+00 0.000e+00 3.388e+06 8.895e-02
179 14084 5.268832e+00 0.000e+00 3.060e+06 5.778e-02
180 14161 5.246358e+00 0.000e+00 4.892e+06 6.756e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
181 14238 5.172598e+00 0.000e+00 5.359e+06 2.527e-02
182 14317 5.173883e+00 0.000e+00 3.433e+06 2.881e-02
183 14394 5.156295e+00 0.000e+00 1.251e+06 1.280e-02
184 14471 5.151894e+00 0.000e+00 5.192e+05 4.005e-02
185 14548 5.148363e+00 0.000e+00 1.464e+05 1.110e-02
186 14625 5.148710e+00 0.000e+00 2.848e+04 2.635e-03
187 14702 5.148730e+00 0.000e+00 1.707e+04 6.931e-04
188 14779 5.148722e+00 0.000e+00 1.294e+04 3.097e-04
189 14856 5.148724e+00 0.000e+00 2.933e+04 3.834e-04
190 14933 5.148701e+00 0.000e+00 6.744e+04 7.115e-04
191 15010 5.148557e+00 0.000e+00 1.360e+05 1.174e-03
192 15087 5.148186e+00 0.000e+00 2.487e+05 1.957e-03
193 15164 5.147156e+00 0.000e+00 4.281e+05 3.318e-03
194 15241 5.144474e+00 0.000e+00 7.126e+05 5.731e-03
195 15318 5.137373e+00 0.000e+00 1.183e+06 1.035e-02
196 15395 5.118769e+00 0.000e+00 2.005e+06 1.968e-02
197 15472 5.070272e+00 0.000e+00 3.427e+06 4.005e-02
198 15549 4.947707e+00 0.000e+00 5.799e+06 8.599e-02
199 15626 4.685957e+00 0.000e+00 8.880e+06 1.786e-01
200 15703 4.419011e+00 0.000e+00 1.016e+07 1.938e-01
201 15780 4.040191e+00 0.000e+00 9.306e+06 1.432e-01
202 15857 4.025285e+00 0.000e+00 6.615e+06 1.208e-01
203 15934 3.745606e+00 0.000e+00 4.237e+06 9.454e-02
204 16012 3.739460e+00 0.000e+00 4.037e+06 4.047e-03
205 16089 3.710066e+00 0.000e+00 3.565e+06 3.074e-02
206 16166 3.692888e+00 0.000e+00 1.637e+06 1.218e-02
207 16243 3.672665e+00 0.000e+00 8.792e+05 4.471e-02
208 16323 3.678176e+00 0.000e+00 9.445e+05 2.669e-03
209 16400 3.665178e+00 0.000e+00 7.775e+05 3.872e-03
210 16477 3.662630e+00 0.000e+00 1.553e+06 2.238e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
211 16555 3.656050e+00 0.000e+00 8.472e+05 5.949e-03
212 16632 3.651548e+00 0.000e+00 3.768e+05 1.178e-02
213 16709 3.651770e+00 0.000e+00 1.281e+05 1.201e-03
214 16786 3.651767e+00 0.000e+00 1.131e+05 1.163e-03
215 16863 3.651918e+00 0.000e+00 3.451e+04 1.878e-03
216 16940 3.651992e+00 0.000e+00 2.085e+04 1.592e-04
217 17017 3.652062e+00 0.000e+00 1.474e+04 4.723e-04
218 17094 3.652078e+00 0.000e+00 8.888e+03 2.126e-04
219 17171 3.652085e+00 0.000e+00 5.423e+03 3.651e-04
220 17248 3.620360e+00 0.000e+00 9.943e+04 2.667e-03
221 17325 3.618763e+00 0.000e+00 1.414e+05 1.724e-03
222 17402 3.618677e+00 0.000e+00 5.934e+04 9.112e-04
223 17479 3.618614e+00 0.000e+00 3.645e+04 8.634e-04
224 17556 3.618595e+00 0.000e+00 1.953e+04 5.345e-04
225 17633 3.618586e+00 0.000e+00 8.597e+03 2.401e-04
226 17710 3.618581e+00 0.000e+00 6.190e+03 9.721e-05
227 17787 3.618576e+00 0.000e+00 1.116e+04 1.797e-04
228 17864 3.618571e+00 0.000e+00 2.378e+04 2.725e-04
229 17941 3.618559e+00 0.000e+00 4.126e+04 4.529e-04
230 18018 3.618533e+00 0.000e+00 6.586e+04 7.098e-04
231 18095 3.618467e+00 0.000e+00 1.029e+05 1.134e-03
232 18172 3.618299e+00 0.000e+00 1.589e+05 1.775e-03
233 18249 3.617865e+00 0.000e+00 2.440e+05 2.750e-03
234 18326 3.616748e+00 0.000e+00 3.721e+05 4.181e-03
235 18403 3.613890e+00 0.000e+00 5.629e+05 6.221e-03
236 18480 3.606687e+00 0.000e+00 8.697e+05 9.044e-03
237 18557 3.589177e+00 0.000e+00 1.345e+06 1.321e-02
238 18634 3.550303e+00 0.000e+00 1.872e+06 2.109e-02
239 18711 3.479791e+00 0.000e+00 2.127e+06 3.543e-02
240 18788 3.383846e+00 0.000e+00 1.890e+06 4.766e-02
First-order Norm of
Iter F-count f(x) Feasibility optimality step
241 18865 3.300714e+00 0.000e+00 1.551e+06 5.518e-02
242 18942 3.282692e+00 0.000e+00 7.261e+05 3.577e-02
243 19019 3.280584e+00 0.000e+00 1.531e+05 2.840e-03
244 19096 3.280321e+00 0.000e+00 7.551e+04 2.551e-03
245 19173 3.280387e+00 0.000e+00 1.132e+05 2.056e-03
246 19250 3.280358e+00 0.000e+00 5.089e+04 3.827e-03
247 19327 3.280414e+00 0.000e+00 3.231e+04 2.209e-03
248 19404 3.280434e+00 0.000e+00 4.759e+04 2.152e-03
249 19481 3.280431e+00 0.000e+00 7.005e+04 3.029e-03
250 19558 3.280298e+00 0.000e+00 1.061e+05 5.175e-03
251 19635 3.279541e+00 0.000e+00 2.097e+05 1.023e-02
252 19712 3.278886e+00 0.000e+00 2.375e+05 5.432e-03
253 19789 3.278927e+00 0.000e+00 2.221e+05 9.914e-04
254 19866 3.278377e+00 0.000e+00 2.946e+05 6.022e-03
255 19943 3.274037e+00 0.000e+00 4.823e+05 2.199e-02
256 20020 3.275730e+00 0.000e+00 3.297e+05 9.746e-03
257 20097 3.273675e+00 0.000e+00 3.631e+05 9.189e-03
258 20174 3.273399e+00 0.000e+00 3.373e+05 2.655e-03
259 20251 3.273279e+00 0.000e+00 2.602e+05 3.595e-03
260 20328 3.273160e+00 0.000e+00 2.587e+05 1.014e-03
261 20405 3.272868e+00 0.000e+00 2.623e+05 7.021e-04
262 20482 3.272513e+00 0.000e+00 2.449e+05 1.933e-03
263 20559 3.272102e+00 0.000e+00 1.819e+05 3.881e-03
264 20636 3.271793e+00 0.000e+00 1.678e+05 3.734e-03
265 20713 3.271508e+00 0.000e+00 1.799e+05 3.747e-03
266 20790 3.271260e+00 0.000e+00 1.548e+05 3.680e-03
267 20867 3.271113e+00 0.000e+00 9.429e+04 3.003e-03
268 20944 3.271079e+00 0.000e+00 7.437e+04 1.512e-03
269 21021 3.271085e+00 0.000e+00 4.322e+04 5.655e-04
270 21098 3.271096e+00 0.000e+00 2.429e+04 3.705e-04
First-order Norm of
Iter F-count f(x) Feasibility optimality step
271 21175 3.271110e+00 0.000e+00 2.057e+04 4.897e-04
272 21252 3.271124e+00 0.000e+00 9.070e+03 4.175e-04
273 21329 3.271134e+00 0.000e+00 3.838e+03 1.709e-04
274 21406 3.271138e+00 0.000e+00 2.511e+03 3.636e-05
275 21483 3.271140e+00 0.000e+00 1.616e+03 1.353e-05
276 21560 3.271140e+00 0.000e+00 2.882e+03 1.734e-05
277 21637 3.271140e+00 0.000e+00 4.543e+03 2.746e-05
278 21714 3.271138e+00 0.000e+00 7.020e+03 4.506e-05
279 21791 3.271136e+00 0.000e+00 1.084e+04 7.406e-05
280 21868 3.271132e+00 0.000e+00 1.684e+04 1.203e-04
281 21945 3.271122e+00 0.000e+00 2.636e+04 1.933e-04
282 22022 3.271095e+00 0.000e+00 4.218e+04 3.073e-04
283 22099 3.271026e+00 0.000e+00 7.085e+04 4.828e-04
284 22176 3.270849e+00 0.000e+00 1.161e+05 7.427e-04
285 22253 3.270404e+00 0.000e+00 1.854e+05 1.107e-03
286 22330 3.269323e+00 0.000e+00 2.834e+05 1.589e-03
287 22407 3.266942e+00 0.000e+00 3.964e+05 2.348e-03
288 22484 3.262728e+00 0.000e+00 4.657e+05 3.999e-03
289 22561 3.257899e+00 0.000e+00 4.486e+05 6.077e-03
290 22638 3.255481e+00 0.000e+00 3.331e+05 5.013e-03
291 22715 3.255094e+00 0.000e+00 1.315e+05 1.822e-03
292 22792 3.255079e+00 0.000e+00 3.071e+04 8.247e-04
293 22869 3.255101e+00 0.000e+00 4.128e+03 2.229e-04
294 22946 3.255114e+00 0.000e+00 1.357e+03 6.504e-05
295 23023 3.248272e+00 0.000e+00 3.323e+04 3.050e-03
296 23100 3.248060e+00 0.000e+00 2.335e+04 6.369e-04
297 23177 3.248047e+00 0.000e+00 1.130e+04 7.137e-04
298 23254 3.248047e+00 0.000e+00 3.106e+03 3.050e-04
299 23331 3.248047e+00 0.000e+00 1.046e+03 1.094e-05
300 23408 3.248048e+00 0.000e+00 2.944e+02 1.463e-05
First-order Norm of
Iter F-count f(x) Feasibility optimality step
301 23485 3.246637e+00 0.000e+00 7.630e+03 6.414e-04
302 23562 3.246633e+00 0.000e+00 2.473e+03 5.741e-05
303 23639 3.246633e+00 0.000e+00 1.297e+03 3.382e-05
304 23716 3.246633e+00 0.000e+00 1.037e+03 2.308e-05
305 23793 3.246633e+00 0.000e+00 1.777e+03 1.893e-05
306 23870 3.246633e+00 0.000e+00 3.019e+03 2.976e-05
307 23947 3.246633e+00 0.000e+00 4.929e+03 4.615e-05
308 24024 3.246632e+00 0.000e+00 8.031e+03 7.501e-05
309 24101 3.246631e+00 0.000e+00 1.302e+04 1.204e-04
310 24178 3.246628e+00 0.000e+00 2.148e+04 1.943e-04
311 24255 3.246619e+00 0.000e+00 3.600e+04 3.117e-04
312 24332 3.246598e+00 0.000e+00 5.949e+04 4.981e-04
313 24409 3.246541e+00 0.000e+00 9.746e+04 7.879e-04
314 24486 3.246395e+00 0.000e+00 1.584e+05 1.224e-03
315 24563 3.246020e+00 0.000e+00 2.541e+05 1.832e-03
316 24640 3.245100e+00 0.000e+00 3.950e+05 2.553e-03
317 24717 3.243059e+00 0.000e+00 5.652e+05 3.175e-03
318 24794 3.239541e+00 0.000e+00 6.569e+05 4.081e-03
319 24871 3.235987e+00 0.000e+00 4.958e+05 5.944e-03
320 24948 3.234296e+00 0.000e+00 1.946e+05 5.407e-03
321 25025 3.233970e+00 0.000e+00 6.012e+04 3.177e-03
322 25102 3.233954e+00 0.000e+00 8.321e+03 1.177e-03
323 25179 3.233954e+00 0.000e+00 1.040e+03 1.561e-04
324 25256 3.233954e+00 0.000e+00 2.277e+02 1.701e-05
325 25333 3.233954e+00 0.000e+00 4.223e+01 3.408e-06
326 25410 3.233671e+00 0.000e+00 1.291e+03 1.635e-04
327 25487 3.233671e+00 0.000e+00 2.265e+02 2.014e-05
328 25564 3.233671e+00 0.000e+00 1.314e+02 2.817e-06
329 25641 3.233671e+00 0.000e+00 6.100e+02 7.427e-06
330 25718 3.233671e+00 0.000e+00 1.257e+03 9.998e-06
First-order Norm of
Iter F-count f(x) Feasibility optimality step
331 25795 3.233671e+00 0.000e+00 2.385e+03 1.743e-05
332 25872 3.233671e+00 0.000e+00 4.162e+03 2.769e-05
333 25949 3.233671e+00 0.000e+00 7.066e+03 4.564e-05
334 26026 3.233670e+00 0.000e+00 1.174e+04 7.485e-05
335 26103 3.233669e+00 0.000e+00 1.929e+04 1.243e-04
336 26180 3.233666e+00 0.000e+00 3.135e+04 2.081e-04
337 26257 3.233657e+00 0.000e+00 5.026e+04 3.518e-04
338 26334 3.233635e+00 0.000e+00 7.824e+04 5.917e-04
339 26411 3.233586e+00 0.000e+00 1.135e+05 9.442e-04
340 26488 3.233494e+00 0.000e+00 1.393e+05 1.256e-03
341 26565 3.233384e+00 0.000e+00 1.197e+05 1.073e-03
342 26642 3.233320e+00 0.000e+00 5.461e+04 7.617e-04
343 26719 3.233306e+00 0.000e+00 1.051e+04 7.047e-04
344 26796 3.233305e+00 0.000e+00 2.282e+03 2.280e-04
345 26873 3.233305e+00 0.000e+00 2.151e+02 2.456e-05
346 26951 3.233305e+00 0.000e+00 1.119e+02 8.575e-07
347 27034 3.233305e+00 0.000e+00 4.062e-06 4.926e-07
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
fval =
3.2333
maxreldifference =
0.0330
Survived first test
Elapsed time is 10.251870 seconds.
>>
Maxreldifference for 1e-15, still larger. but it keeps changing each time i run.
> fminicon_WR_N
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 77 4.303459e+14 0.000e+00 7.521e+16
1 155 2.661174e+10 0.000e+00 2.023e+12 3.866e-01
2 232 2.481525e+09 0.000e+00 6.646e+10 2.709e-01
3 309 3.681385e+08 0.000e+00 4.769e+09 5.142e-01
4 387 2.773564e+08 0.000e+00 2.664e+09 2.145e-01
5 464 2.409726e+08 0.000e+00 4.014e+09 2.934e-01
6 542 1.305296e+08 0.000e+00 1.850e+09 8.469e-02
7 620 1.260598e+08 0.000e+00 1.466e+09 9.448e-02
8 697 1.222390e+08 0.000e+00 2.254e+09 8.393e-02
9 775 8.514194e+07 0.000e+00 4.096e+08 4.040e-02
10 854 8.174094e+07 0.000e+00 3.990e+08 3.990e-02
11 936 7.812439e+07 0.000e+00 4.549e+08 5.283e-02
12 1013 7.307643e+07 0.000e+00 4.399e+08 5.763e-02
13 1091 6.848275e+07 0.000e+00 2.054e+08 6.959e-02
14 1170 6.482910e+07 0.000e+00 1.159e+08 2.917e-02
15 1250 6.442925e+07 0.000e+00 1.136e+08 1.494e-02
16 1331 6.288494e+07 0.000e+00 1.024e+08 4.057e-02
17 1408 6.145740e+07 0.000e+00 9.950e+07 9.230e-02
18 1486 5.915300e+07 0.000e+00 1.216e+08 8.636e-02
19 1565 5.662743e+07 0.000e+00 7.025e+07 3.228e-02
20 1643 5.605899e+07 0.000e+00 5.362e+07 3.886e-02
21 1720 5.446974e+07 0.000e+00 5.941e+07 4.411e-02
22 1798 5.359199e+07 0.000e+00 1.919e+08 1.780e-01
23 1880 4.991405e+07 0.000e+00 9.685e+07 6.723e-02
24 1959 4.798018e+07 0.000e+00 2.491e+07 2.891e-02
25 2037 4.743422e+07 0.000e+00 5.182e+07 3.887e-02
26 2118 4.631176e+07 0.000e+00 1.005e+08 8.247e-02
27 2200 4.571072e+07 0.000e+00 1.304e+08 7.513e-02
28 2280 4.569498e+07 0.000e+00 9.073e+07 1.340e-02
29 2361 4.330618e+07 0.000e+00 1.750e+07 2.880e-02
30 2439 4.192392e+07 0.000e+00 8.920e+07 1.484e-01
First-order Norm of
Iter F-count f(x) Feasibility optimality step
31 2516 2.443732e+07 0.000e+00 5.587e+08 2.727e+00
32 2595 2.419338e+07 0.000e+00 3.004e+08 2.642e-01
33 2675 1.886331e+07 0.000e+00 1.746e+08 4.886e-01
34 2753 1.220467e+07 0.000e+00 2.030e+08 6.009e-01
35 2831 9.798720e+06 0.000e+00 9.587e+07 3.141e-01
36 2909 7.424357e+06 0.000e+00 5.623e+07 4.440e-01
37 2986 1.917160e+06 0.000e+00 7.146e+06 2.339e+00
38 3063 7.411915e+05 0.000e+00 2.263e+06 2.881e-01
39 3140 1.870715e+05 0.000e+00 6.237e+05 1.724e+00
40 3219 9.675549e+04 0.000e+00 8.544e+05 5.433e-01
41 3296 5.001924e+04 0.000e+00 2.947e+05 1.500e-01
42 3373 2.913585e+04 0.000e+00 1.227e+06 5.069e-01
43 3450 2.165305e+04 0.000e+00 1.356e+06 9.704e-02
44 3527 2.125459e+04 0.000e+00 1.347e+06 1.533e-02
45 3604 1.405611e+03 0.000e+00 1.719e+07 6.034e-01
46 3681 1.029196e+03 0.000e+00 4.518e+07 2.491e-02
47 3758 1.002775e+03 0.000e+00 5.221e+07 1.470e-03
48 3835 4.308034e+02 0.000e+00 1.522e+07 2.203e-01
49 3912 3.753135e+02 0.000e+00 5.334e+06 1.556e-02
50 3989 2.969191e+02 0.000e+00 6.556e+06 3.270e-02
51 4066 2.415614e+02 0.000e+00 3.067e+06 2.965e-02
52 4143 1.605061e+02 0.000e+00 6.606e+06 4.977e-02
53 4220 1.489002e+02 0.000e+00 7.769e+06 1.131e-02
54 4297 1.465537e+02 0.000e+00 5.637e+06 2.517e-03
55 4374 7.830231e+01 0.000e+00 3.312e+06 8.947e-02
56 4451 7.638627e+01 0.000e+00 3.259e+06 3.868e-03
57 4528 6.649456e+01 0.000e+00 1.191e+06 2.454e-03
58 4605 5.951218e+01 0.000e+00 5.450e+05 2.527e-03
59 4682 2.300749e+01 0.000e+00 8.917e+05 1.088e-02
60 4759 2.106193e+01 0.000e+00 7.189e+05 2.123e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
61 4836 1.979498e+01 0.000e+00 2.038e+06 3.211e-03
62 4913 1.914413e+01 0.000e+00 2.984e+07 9.194e-06
63 4991 1.904688e+01 0.000e+00 3.805e+07 4.505e-04
64 5072 1.702621e+01 0.000e+00 1.939e+02 4.590e-03
65 5149 1.657335e+01 0.000e+00 1.441e+06 3.403e-03
66 5226 1.573982e+01 0.000e+00 8.925e+06 1.730e-03
67 5303 1.573454e+01 0.000e+00 2.524e+07 8.407e-05
68 5380 1.562370e+01 0.000e+00 2.493e+07 2.944e-06
69 5457 1.491619e+01 0.000e+00 1.226e+05 1.537e-04
70 5534 1.490203e+01 0.000e+00 2.740e+05 2.311e-05
71 5611 1.489220e+01 0.000e+00 6.119e+05 1.098e-04
72 5688 1.486510e+01 0.000e+00 1.114e+06 2.515e-04
73 5765 1.485222e+01 0.000e+00 5.419e+05 1.914e-04
74 5842 1.484909e+01 0.000e+00 6.103e+05 9.383e-06
75 5919 1.484445e+01 0.000e+00 7.147e+05 1.470e-05
76 5996 1.483969e+01 0.000e+00 1.327e+05 1.380e-05
77 6073 1.479915e+01 0.000e+00 7.981e+05 1.378e-04
78 6150 1.401198e+01 0.000e+00 7.385e+06 1.761e-03
79 6228 1.366713e+01 0.000e+00 1.518e+07 4.534e-04
80 6306 1.341499e+01 0.000e+00 2.040e+07 7.362e-04
81 6383 1.333486e+01 0.000e+00 1.860e+07 1.514e-03
82 6460 1.328935e+01 0.000e+00 1.810e+07 2.129e-04
83 6544 1.327186e+01 0.000e+00 2.461e+04 4.836e-04
84 6625 1.323880e+01 0.000e+00 2.645e+00 1.207e-03
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
fval =
13.2388
maxreldifference =
19.5333
Survived first test
Elapsed time is 2.068225 seconds.
This is the best so far but how can I maintain this random values. Thanks.
>> fminicon_WR_N
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 77 3.876741e+20 0.000e+00 1.986e+23
1 155 2.481087e+13 0.000e+00 3.679e+15 5.407e-01
2 233 1.314554e+11 0.000e+00 1.865e+13 3.521e-01
3 310 3.994948e+09 0.000e+00 1.082e+11 2.065e-01
4 389 9.724643e+08 0.000e+00 4.668e+10 1.325e-01
5 467 5.146788e+08 0.000e+00 7.112e+09 3.770e-02
6 545 3.818505e+08 0.000e+00 2.869e+09 3.502e-02
7 622 3.147298e+08 0.000e+00 1.510e+09 3.947e-02
8 699 2.721072e+08 0.000e+00 1.113e+09 4.573e-02
9 776 2.392267e+08 0.000e+00 1.046e+09 4.237e-02
10 853 2.123600e+08 0.000e+00 9.219e+08 3.887e-02
11 932 2.062514e+08 0.000e+00 7.071e+08 9.075e-03
12 1009 2.004144e+08 0.000e+00 6.330e+08 9.093e-03
13 1086 1.948134e+08 0.000e+00 6.133e+08 9.000e-03
14 1163 1.894362e+08 0.000e+00 5.865e+08 8.911e-03
15 1240 1.842735e+08 0.000e+00 5.589e+08 8.829e-03
16 1317 1.793164e+08 0.000e+00 5.320e+08 8.755e-03
17 1394 1.745567e+08 0.000e+00 5.062e+08 8.688e-03
18 1471 1.699866e+08 0.000e+00 4.815e+08 8.629e-03
19 1548 1.655990e+08 0.000e+00 4.580e+08 8.576e-03
20 1625 1.613866e+08 0.000e+00 4.354e+08 8.531e-03
21 1702 1.573429e+08 0.000e+00 4.139e+08 8.493e-03
22 1779 1.534612e+08 0.000e+00 3.933e+08 8.462e-03
23 1856 1.497354e+08 0.000e+00 3.736e+08 8.439e-03
24 1933 1.461591e+08 0.000e+00 3.548e+08 8.423e-03
25 2010 1.427263e+08 0.000e+00 3.369e+08 8.415e-03
26 2088 1.410600e+08 0.000e+00 3.282e+08 4.207e-03
27 2165 1.394274e+08 0.000e+00 3.197e+08 4.209e-03
28 2242 1.378277e+08 0.000e+00 3.115e+08 4.212e-03
29 2319 1.362602e+08 0.000e+00 3.034e+08 4.215e-03
30 2396 1.347244e+08 0.000e+00 2.956e+08 4.219e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1111 85635 3.207875e+07 0.000e+00 2.543e+06 1.580e-03
1112 85712 3.204804e+07 0.000e+00 2.539e+06 1.580e-03
1113 85789 3.201736e+07 0.000e+00 2.535e+06 1.579e-03
1114 85866 3.198671e+07 0.000e+00 2.530e+06 1.579e-03
1115 85943 3.195609e+07 0.000e+00 2.526e+06 1.578e-03
1116 86020 3.192550e+07 0.000e+00 2.522e+06 1.578e-03
1117 86097 3.189494e+07 0.000e+00 2.518e+06 1.577e-03
1118 86174 3.186440e+07 0.000e+00 2.513e+06 1.577e-03
1119 86251 3.183390e+07 0.000e+00 2.509e+06 1.576e-03
1120 86328 3.180342e+07 0.000e+00 2.505e+06 1.576e-03
1121 86405 3.177297e+07 0.000e+00 2.501e+06 1.575e-03
1122 86482 3.174256e+07 0.000e+00 2.497e+06 1.575e-03
1123 86559 3.171217e+07 0.000e+00 2.492e+06 1.574e-03
1124 86636 3.168181e+07 0.000e+00 2.488e+06 1.574e-03
1125 86713 3.165148e+07 0.000e+00 2.484e+06 1.573e-03
1126 86790 3.162118e+07 0.000e+00 2.480e+06 1.573e-03
1127 86867 3.159090e+07 0.000e+00 2.476e+06 1.572e-03
1128 86944 3.156066e+07 0.000e+00 2.472e+06 1.572e-03
1129 87021 3.153044e+07 0.000e+00 2.468e+06 1.571e-03
1130 87098 3.150026e+07 0.000e+00 2.463e+06 1.571e-03
1131 87175 3.147010e+07 0.000e+00 2.459e+06 1.570e-03
1132 87252 3.143997e+07 0.000e+00 2.455e+06 1.570e-03
1133 87329 3.140987e+07 0.000e+00 2.451e+06 1.569e-03
1134 87406 3.137980e+07 0.000e+00 2.447e+06 1.569e-03
1135 87483 3.134976e+07 0.000e+00 2.443e+06 1.568e-03
1136 87560 3.131974e+07 0.000e+00 2.439e+06 1.567e-03
1137 87637 3.128976e+07 0.000e+00 2.435e+06 1.567e-03
1138 87714 3.125980e+07 0.000e+00 2.431e+06 1.566e-03
1139 87791 3.122987e+07 0.000e+00 2.427e+06 1.566e-03
1140 87868 3.119997e+07 0.000e+00 2.423e+06 1.565e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1141 87945 3.117010e+07 0.000e+00 2.419e+06 1.565e-03
1142 88022 3.114026e+07 0.000e+00 2.415e+06 1.564e-03
1143 88099 3.111044e+07 0.000e+00 2.411e+06 1.564e-03
1144 88176 3.108066e+07 0.000e+00 2.407e+06 1.563e-03
1145 88253 3.105090e+07 0.000e+00 2.403e+06 1.563e-03
1146 88330 3.102117e+07 0.000e+00 2.399e+06 1.562e-03
1147 88407 3.099147e+07 0.000e+00 2.395e+06 1.562e-03
1148 88484 3.096180e+07 0.000e+00 2.391e+06 1.561e-03
1149 88561 3.093215e+07 0.000e+00 2.387e+06 1.561e-03
1150 88638 3.090254e+07 0.000e+00 2.383e+06 1.560e-03
1151 88715 3.087295e+07 0.000e+00 2.379e+06 1.560e-03
1152 88792 3.084339e+07 0.000e+00 2.375e+06 1.559e-03
1153 88869 3.081386e+07 0.000e+00 2.371e+06 1.559e-03
1154 88946 3.078435e+07 0.000e+00 2.367e+06 1.558e-03
1155 89023 3.075488e+07 0.000e+00 2.363e+06 1.558e-03
1156 89100 3.072543e+07 0.000e+00 2.359e+06 1.557e-03
1157 89177 3.069601e+07 0.000e+00 2.355e+06 1.557e-03
1158 89254 3.066662e+07 0.000e+00 2.351e+06 1.556e-03
1159 89331 3.063726e+07 0.000e+00 2.347e+06 1.556e-03
1160 89408 3.060792e+07 0.000e+00 2.343e+06 1.555e-03
1161 89485 3.057861e+07 0.000e+00 2.340e+06 1.555e-03
1162 89562 3.054933e+07 0.000e+00 2.336e+06 1.554e-03
1163 89639 3.052008e+07 0.000e+00 2.332e+06 1.554e-03
1164 89716 3.049086e+07 0.000e+00 2.328e+06 1.553e-03
1165 89793 3.046166e+07 0.000e+00 2.324e+06 1.553e-03
1166 89870 3.043249e+07 0.000e+00 2.320e+06 1.552e-03
1167 89947 3.040335e+07 0.000e+00 2.317e+06 1.552e-03
1168 90024 3.037424e+07 0.000e+00 2.313e+06 1.551e-03
1169 90101 3.034515e+07 0.000e+00 2.309e+06 1.551e-03
1170 90178 3.031610e+07 0.000e+00 2.305e+06 1.550e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1171 90255 3.028707e+07 0.000e+00 2.301e+06 1.549e-03
1172 90332 3.025807e+07 0.000e+00 2.297e+06 1.549e-03
1173 90409 3.022909e+07 0.000e+00 2.294e+06 1.548e-03
1174 90486 3.020014e+07 0.000e+00 2.290e+06 1.548e-03
1175 90563 3.017122e+07 0.000e+00 2.286e+06 1.547e-03
1176 90640 3.014233e+07 0.000e+00 2.282e+06 1.547e-03
1177 90717 3.011347e+07 0.000e+00 2.279e+06 1.546e-03
1178 90794 3.008463e+07 0.000e+00 2.275e+06 1.546e-03
1179 90871 3.005582e+07 0.000e+00 2.271e+06 1.545e-03
1180 90948 3.002704e+07 0.000e+00 2.267e+06 1.545e-03
1181 91025 2.999828e+07 0.000e+00 2.264e+06 1.544e-03
1182 91102 2.996956e+07 0.000e+00 2.260e+06 1.544e-03
1183 91179 2.994086e+07 0.000e+00 2.256e+06 1.543e-03
1184 91256 2.991218e+07 0.000e+00 2.253e+06 1.543e-03
1185 91333 2.988354e+07 0.000e+00 2.249e+06 1.542e-03
1186 91410 2.985492e+07 0.000e+00 2.245e+06 1.542e-03
1187 91487 2.982633e+07 0.000e+00 2.242e+06 1.541e-03
1188 91564 2.979776e+07 0.000e+00 2.238e+06 1.541e-03
1189 91641 2.976923e+07 0.000e+00 2.234e+06 1.540e-03
1190 91718 2.974072e+07 0.000e+00 2.231e+06 1.540e-03
1191 91795 2.971224e+07 0.000e+00 2.227e+06 1.539e-03
1192 91872 2.968378e+07 0.000e+00 2.223e+06 1.539e-03
1193 91949 2.965535e+07 0.000e+00 2.220e+06 1.538e-03
1194 92026 2.962695e+07 0.000e+00 2.216e+06 1.538e-03
1195 92103 2.959858e+07 0.000e+00 2.212e+06 1.537e-03
1196 92180 2.957023e+07 0.000e+00 2.209e+06 1.537e-03
1197 92257 2.954191e+07 0.000e+00 2.205e+06 1.536e-03
1198 92334 2.951362e+07 0.000e+00 2.202e+06 1.536e-03
1199 92411 2.948535e+07 0.000e+00 2.198e+06 1.535e-03
1200 92488 2.945711e+07 0.000e+00 2.194e+06 1.534e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1201 92565 2.942890e+07 0.000e+00 2.191e+06 1.534e-03
1202 92642 2.940071e+07 0.000e+00 2.187e+06 1.533e-03
1203 92719 2.937255e+07 0.000e+00 2.184e+06 1.533e-03
1204 92796 2.934442e+07 0.000e+00 2.180e+06 1.532e-03
1205 92873 2.931631e+07 0.000e+00 2.177e+06 1.532e-03
1206 92950 2.928823e+07 0.000e+00 2.173e+06 1.531e-03
1207 93027 2.926018e+07 0.000e+00 2.169e+06 1.531e-03
1208 93104 2.923216e+07 0.000e+00 2.166e+06 1.530e-03
1209 93181 2.920416e+07 0.000e+00 2.162e+06 1.530e-03
1210 93258 2.917619e+07 0.000e+00 2.159e+06 1.529e-03
1211 93335 2.914824e+07 0.000e+00 2.155e+06 1.529e-03
1212 93412 2.912032e+07 0.000e+00 2.152e+06 1.528e-03
1213 93489 2.909243e+07 0.000e+00 2.148e+06 1.528e-03
1214 93566 2.906456e+07 0.000e+00 2.145e+06 1.527e-03
1215 93643 2.903672e+07 0.000e+00 2.141e+06 1.527e-03
1216 93720 2.900891e+07 0.000e+00 2.138e+06 1.526e-03
1217 93797 2.898112e+07 0.000e+00 2.134e+06 1.526e-03
1218 93874 2.895336e+07 0.000e+00 2.131e+06 1.525e-03
1219 93951 2.892563e+07 0.000e+00 2.128e+06 1.525e-03
1220 94028 2.889792e+07 0.000e+00 2.124e+06 1.524e-03
1221 94105 2.887024e+07 0.000e+00 2.121e+06 1.524e-03
1222 94182 2.884258e+07 0.000e+00 2.117e+06 1.523e-03
1223 94259 2.881496e+07 0.000e+00 2.114e+06 1.523e-03
1224 94336 2.878735e+07 0.000e+00 2.110e+06 1.522e-03
1225 94413 2.875978e+07 0.000e+00 2.107e+06 1.521e-03
1226 94490 2.873223e+07 0.000e+00 2.104e+06 1.521e-03
1227 94567 2.870470e+07 0.000e+00 2.100e+06 1.520e-03
1228 94644 2.867720e+07 0.000e+00 2.097e+06 1.520e-03
1229 94721 2.864973e+07 0.000e+00 2.093e+06 1.519e-03
1230 94798 2.862229e+07 0.000e+00 2.090e+06 1.519e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1231 94875 2.859487e+07 0.000e+00 2.087e+06 1.518e-03
1232 94952 2.856747e+07 0.000e+00 2.083e+06 1.518e-03
1233 95029 2.854011e+07 0.000e+00 2.080e+06 1.517e-03
1234 95106 2.851277e+07 0.000e+00 2.077e+06 1.517e-03
1235 95183 2.848545e+07 0.000e+00 2.073e+06 1.516e-03
1236 95260 2.845816e+07 0.000e+00 2.070e+06 1.516e-03
1237 95337 2.843090e+07 0.000e+00 2.067e+06 1.515e-03
1238 95414 2.840366e+07 0.000e+00 2.063e+06 1.515e-03
1239 95491 2.837645e+07 0.000e+00 2.060e+06 1.514e-03
1240 95568 2.834926e+07 0.000e+00 2.057e+06 1.514e-03
1241 95645 2.832210e+07 0.000e+00 2.053e+06 1.513e-03
1242 95722 2.829497e+07 0.000e+00 2.050e+06 1.513e-03
1243 95799 2.826786e+07 0.000e+00 2.047e+06 1.512e-03
1244 95876 2.824078e+07 0.000e+00 2.043e+06 1.512e-03
1245 95953 2.821372e+07 0.000e+00 2.040e+06 1.511e-03
1246 96030 2.818669e+07 0.000e+00 2.037e+06 1.511e-03
1247 96107 2.815968e+07 0.000e+00 2.034e+06 1.510e-03
1248 96184 2.813270e+07 0.000e+00 2.030e+06 1.509e-03
1249 96261 2.810575e+07 0.000e+00 2.027e+06 1.509e-03
1250 96338 2.807882e+07 0.000e+00 2.024e+06 1.508e-03
1251 96415 2.805192e+07 0.000e+00 2.021e+06 1.508e-03
1252 96492 2.802504e+07 0.000e+00 2.017e+06 1.507e-03
1253 96569 2.799819e+07 0.000e+00 2.014e+06 1.507e-03
1254 96646 2.797136e+07 0.000e+00 2.011e+06 1.506e-03
1255 96723 2.794456e+07 0.000e+00 2.008e+06 1.506e-03
1256 96800 2.791778e+07 0.000e+00 2.004e+06 1.505e-03
1257 96877 2.789103e+07 0.000e+00 2.001e+06 1.505e-03
1258 96954 2.786431e+07 0.000e+00 1.998e+06 1.504e-03
1259 97031 2.783761e+07 0.000e+00 1.995e+06 1.504e-03
1260 97108 2.781094e+07 0.000e+00 1.992e+06 1.503e-03
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1261 97185 2.778429e+07 0.000e+00 1.988e+06 1.503e-03
1262 97262 2.775766e+07 0.000e+00 1.985e+06 1.502e-03
1263 97339 2.773107e+07 0.000e+00 1.982e+06 1.502e-03
1264 97416 2.770449e+07 0.000e+00 1.979e+06 1.501e-03
1265 97493 2.767794e+07 0.000e+00 1.976e+06 1.501e-03
1266 97570 2.765142e+07 0.000e+00 1.973e+06 1.500e-03
1267 97647 2.762492e+07 0.000e+00 1.969e+06 1.500e-03
1268 97724 2.759845e+07 0.000e+00 1.966e+06 1.499e-03
1269 97801 2.757201e+07 0.000e+00 1.963e+06 1.499e-03
1270 97878 2.754558e+07 0.000e+00 1.960e+06 1.498e-03
1271 97955 2.751919e+07 0.000e+00 1.957e+06 1.497e-03
1272 98032 2.749282e+07 0.000e+00 1.954e+06 1.497e-03
1273 98109 2.746647e+07 0.000e+00 1.951e+06 1.496e-03
1274 98186 2.744015e+07 0.000e+00 1.948e+06 1.496e-03
1275 98263 2.741385e+07 0.000e+00 1.944e+06 1.495e-03
1276 98340 2.738758e+07 0.000e+00 1.941e+06 1.495e-03
1277 98417 2.736133e+07 0.000e+00 1.938e+06 1.494e-03
1278 98494 2.733511e+07 0.000e+00 1.935e+06 1.494e-03
1279 98571 2.730891e+07 0.000e+00 1.932e+06 1.493e-03
1280 98648 2.728274e+07 0.000e+00 1.929e+06 1.493e-03
1281 98725 2.725659e+07 0.000e+00 1.926e+06 1.492e-03
1282 98802 2.723047e+07 0.000e+00 1.923e+06 1.492e-03
1283 98879 2.720437e+07 0.000e+00 1.920e+06 1.491e-03
1284 98956 2.717830e+07 0.000e+00 1.917e+06 1.491e-03
1285 99033 2.715225e+07 0.000e+00 1.914e+06 1.490e-03
1286 99110 2.712623e+07 0.000e+00 1.911e+06 1.490e-03
1287 99187 2.710023e+07 0.000e+00 1.908e+06 1.489e-03
1288 99264 2.707426e+07 0.000e+00 1.905e+06 1.489e-03
1289 99341 2.704831e+07 0.000e+00 1.902e+06 1.488e-03
1290 99419 2.703534e+07 0.000e+00 1.900e+06 7.438e-04
First-order Norm of
Iter F-count f(x) Feasibility optimality step
1291 99496 2.702238e+07 0.000e+00 1.899e+06 7.436e-04
1292 99573 2.700943e+07 0.000e+00 1.897e+06 7.435e-04
1293 99650 2.699649e+07 0.000e+00 1.896e+06 7.434e-04
1294 99727 2.698355e+07 0.000e+00 1.894e+06 7.432e-04
1295 99804 2.697061e+07 0.000e+00 1.893e+06 7.431e-04
1296 99881 2.695769e+07 0.000e+00 1.891e+06 7.430e-04
1297 99958 2.694477e+07 0.000e+00 1.890e+06 7.428e-04
1298 100035 2.693185e+07 0.000e+00 1.888e+06 7.427e-04
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 1.000000e+05.
fval =
2.6932e+07
maxreldifference =
6.0210e-09
Survived first test
Elapsed time is 28.981878 seconds.
>>
tol and maxreldifference are not related.
maxreldifference is not actually a measure of how "good" the solution is: maxreldifference is a measure of how stable a solution is. It tests: if you move one of the variables just a little, then how much does the output change ?
There are a few different reasons that maxreldifference could be high:
  • testX(K) = testX(K) + 1e-10; -- if you lower tol below the previous 1e-8 then that 1e-10 that I add in that line of code might be a significant relative change to the existing value. With tol of 1e-15 then 1e-10 could be a large relative change. The line should probably be coded something like testX(K) = testX(K) + 100*eps(textX(K));
  • In general a function could be really steep. However, when I look, I do not see anything raised to a power greater than 22/5 in the numerator
  • Most of the entries have division by a variable that is raised to the 5th power. If the variable being divided by is small, then the division can end up multiplying the numerator by a lot -- and adding 1e-10 to such a small variable could result in the division being by a larger value (and so not ending up multiplying by as much)
You can use any x0 you want, it does not have to be created by rand().
Before we had an idea of what the initial value should look like, but after I changed to put in the constraints, I had no more idea of what the values should be, so I initialized randomly. You could initialize with constants if you wanted.
Thanks very much for the explanation on the maxrelfdiffernce and tol. It is better understoood now. I appreciate all your selfless help.
Please what will I conclude with that my model is indeed solved, though not a perfect solution. E.g say if the variable is less than the tolerance or tolerance less than the variable. Which is the best way to explain that.
Thanks.
My memory of seeing the results is that you cannot conclude very much.
Your values changed a lot near the lower bound. You would have to explain why a lower bound of (say) 1e-12 is reasonable but a tolerance of (say) 1e-25 would not be reasonable. I think you said that they represented prices and quantities? If so then what is the minimum price step, or the minimum quantity? If you cannot purchase less than 1/100th of a share, then it does not make sense to allow the program to chase down to 1e-13 of a share.
The fact that you got substantially different values out depending on the random inputs should be of concern to you.
The fact that the relative movement on some of the variables is not trivial near the minima tells you that the surface is not stable there.
... it is possible I am remembering back to earlier versions of the code, or I might be confusing the situation with code I was working on for someone else... but at the moment I would not trust the results of this code.
Thanks for the response. Please are you saying you dont trust the results of this code above. I just want to know if is the "tol" that I can use to explain the results of the code. I still did not understand your statement, a bit vague to me.
I just want to know if is the "tol" that I can use to explain the results of the code.
NO
I still did not understand your statement, a bit vague to me.
Non-vague version:
You need to redo your analysis. With your current analysis, your thesis should not be published.
Please can you explain it better for me, are you saying all that I have done is wrong, I thought you said there is not going to be a perfect solution and that I should take the results like that. But why then are you saying I should redo the analysis. Because I accepted this answer and thought that solves the problem but from what you saying is like the answer is not right as you said.
What can I do to improve my code?? Currently, I feel good about the model but explaining it better in terms of the solution is my problem.
I am willing to improve on this code for better results, please help me to know which better way to that. i am still figuring it out myself here.
The fact that you got substantially different values out depending on the random inputs should be of concern to you.
I think you are right, the fact that random input give different output makes my model not to be solved well. I am still checking on how I can fix it. But please do let me know in case you have a better suggestion for me. I think the problem maybe due to my equations that I use in solving the model. Checking all over again.
Thanks.
Please can you help me fix this issue. I encountered this problem when I used 33 countries and 12 sectors instead of the initial 4 countries and 2 sectors. Below is the error and my code attached.
Thanks.
>> Calibration
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 861)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Calibration (line 162)
[x, fval ] = fmincon(GGG, x0, A, b, Aeq, beq, lb, ub, nonlcon, opts);
>>
Please can you help me fix this issue. I encountered this problem when I used 33 countries and 12 sectors instead of the initial 4 countries and 2 sectors. Below is the error and my code attached. The "calibration" file is the one with 33 countries and 12 sectors.
Thanks.
>> Calibration
Error using barrier
Objective function is undefined at initial point. Fmincon cannot continue.
Error in fmincon (line 861)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Calibration (line 162)
[x, fval ] = fmincon(GGG, x0, A, b, Aeq, beq, lb, ub, nonlcon, opts);
You have
load('EORA_data');
That loads several matrices, including VA and GO_agg
va = sum(VA,1)';
beta = va./GO_agg; %use VA/GO data moment
Columns 26, 62, 252 of your VA are such that they total more than the correspondign GO_agg entries -- so va(26) > GO_agg(26) for example. So for those three columns, beta is greater than 1.
These values are loaded from the file, with the only processing being the summation of the columns in VA, so this relationship of beta being greater than 1 is inherent in the data, and is not the result of some subtle calculation mistake.
Then inside GE_solve you have
AA = beta./(1-beta); %cs-1
as noted above, a few of the entries in beta are greater than 1, so 1-beta is negative for those entries, so the corresponding parts of AA will be negative.
CC = AA .* BB_cs; %cs-1
BB_cs is all positive, a few elements of AA are negative, so the corresponding positions in CC are negative.
Lmat = qq .* (CC).^(1-beta);
Some elements in CC are negative, as discussed. A negative number raised to a fraction is complex, so Lmat has some complex entries.
Those complex values "pollute" the rest of the calculation. And even if they did not, you later have
pimat = (beta.^(-beta).*(1-beta).^(-1+beta)).* (wis.^beta) .* PPmat_cs ./Ais;
but with 1-beta being negative in places, that expression calculates complex values as well.
GGG=@(x) sum(GEsolve(reshape(x,Ncoun,Ncoun*Nsec+Ncoun*Nsec+Nsec+1)).^2,'all');
sum of squares is not good enough to calculate goodness of fit when some of the values might be complex. If complex values are to be allowed, you would need norm() or norm^2 instead.
Later in the code you have
x = lsqnonlin('GEsolve',x0,lb,ub,options);
However, lsqnonlin() does not permit using lb and ub when fitting a function that returns complex values, because lb and ub are strictly real-valued, but lsqnonlin() needs to use complex coefficients to fit a function that returns complex values.
Thanks for the response Walter. I did fixed it and betas are all below one now but the model solved immaturely both for fmincon and lsqnonlin. So I did not obtain any results. Below are the errors. I have also attached the updated code.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%fmincon
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 26566 1.503199e+18 0.000e+00 4.309e+13
1 53132 1.502075e+18 0.000e+00 2.014e+12 4.041e+00
Error using horzcat
Requested 26565x26565 (10.5GB) array exceeds maximum array size preference (8.0GB). This might
cause MATLAB to become unresponsive.
Error in formAndFactorKKTmatrix
Error in formAndFactorKKTmatrix
Error in computeTrialStep
Error in barrier
Error in fmincon (line 861)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in Calibration (line 174)
[x, fval ] = fmincon(GGG, x0, A, b, Aeq, beq, lb, ub, nonlcon, opts);
Related documentation
You are asking to optimize 33*805 = 26565 variables.
fmincon needs to estimate the jacobian -- which requires comparing every variable to every other variable. That requires a 26565 x 26565 array of doubles. Which requires more than 10 gigabytes just for that one array.
However, your computer only has 8 gigabytes.
The problem is too large for your computer.
Optimizing a system with over 25000 variables is going to be very slow. And you are unlikely to get a good minima in a reasonable amount of time. I would expect... months of computation, at least.
As you are not using nonlinear constraints, you should consider using an optimizer that does not calculate jacobians, such as fminsearch() or ga()
Thanks for the response, please how do I use Fminsearch or gal(). Can you please help me with that code on fminsearh. Also, how about fixed point iteration method? I will appreciate if you can help me with some simple code of a different solver, or let me know about the fminsearch and Fixed point iteration. I am still new to matlab so sorry if i am asking too much.
My test with ga() suggests that your computation would need at least 36 Gb of memory -- though perhaps that could be reduced by using a smaller population.
Please I do not have that space on my macbook, my memory is only 8GB. Please how about fixed point iteration method or newton raphson method. I was thinking those two will be faster as some people have used that to solve for larger countries. But I don't know how to implement that. So I will appreciate if you can help me with that. I tried one on newton raphson but still stuck on that. Please I really need help.
Thanks.
Please can you check this for me. I tried using the newton Raphson method. It solved quickly without any error but i dont think i did it rightly.
Please can you check my code on newton Raphson method attached above. Actually, i am not sure of it because of the results I am getting. Also, I am new to this method of solving and have minimal idea on that. I will appreciate if you can help me on this.
Thanks,
Celestine.
I have attached the result of running your Calibration function (not the Newton Raphson version). It took several days to run, peaking at about 48 gigabytes of memory. The results are Not Good.
Most of the calculation time appears to have been spent in trying to figure out the new positions to move to, taking into account the bounds constraints. For reasons I do not presently understand, that requires creating matrices of size 26565 x 26565, and involves a bunch of random numbers, but barely involves the current positions (other than to test if they are right against the bounds or not.)
Thanks you for this results Walter. I really appreciate it. But please can you help me in solving with a Fixed Point Iteration method or Newton Raphson method. i really prefer the Fixed Point method but a bit stuck on that.
Please how about the fixed point iteration method. Can you give some guide on that. I think that will be straightforward but I am a bit stuck on that.
Thanks.
No. I feel as if you are relying on me to write and debug your programs, and I am no longer interested. It is up to you to be the primary person to write and debug your code. If you have specific error messages, then someone might be willing to help you to that limited extent.
Please I do not mean you should solve for me, I meant you should give me some guidelines on using the fixed point iteration method. I will then solve it myself with that approach and only contact you when I have some errors.
Thanks,
Celestine
Please can you check the below code for me. I used fixed point iteration to solve but I get all output to be NAN. which I believe is wrong. Please kindly check for me. Attached is my matlab code.
Thanks,
Celestine.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2021a

Preguntada:

el 3 de Sept. de 2021

Editada:

el 10 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by