I'm trying to solve a big quadratic optimization problem using CPLEX (cplexqp) in matlab. Unfortunately by H matrix (or Q matrix as some sources call it) is non-convex in nature and thus I want to set the optimality target from 0 (default) to 3 to tell CPLEX to not terminate when finding out Q is non-convex. However, I'm not sure how to do this. I tried to read the manuals and instructions and they all just said set optimality target = 2 or 3 without any actual examples or general command on how to do it. I tried to do it in options but got an error that CPLEX doesn't recognize 'optimalitytarget'.
options = cplexoptimset('Display','on','TolFun',0.0000001,'TolRLPFun',0.0000001,'MaxNodes',50000,'MaxIter',50000, 'optimalitytarget',3);
I also tried:
Cplex = cplexoptimset('cplex')
Cplex.Param.optimalitytarget = 3;
without any sucess. I know it the API is Cplex.Param.optimalitytarget but I cannot seem to figure out where to set this.
Sorry if this is a trivial or dumb question. I feel like this is one of the things that's very simple and either you do know or you don't know and I don't know how to do it. Any help or advice on going about this is greatly appreciated.
You can find examples of using CPLEX from within MATLAB in the distribution. They are located in [installPath]/cplex/examples/src/matlab.
You mentioned that you are using cplexqp, which is the toolbox API. Looking at https://www.ibm.com/support/knowledgecenter/es/SSSA5P_12.7.0/ilog.odms.cplex.help/CPLEX/MATLAB/topics/gs_param.html, I suspect that the issue with your second example is with your using Param. That structure relates to the Cplex Class API, not the toolbox API. I suppose that the following would work better:
options = cplexoptimset('cplex');
options.optimalitytarget=3;
Model = cplex.Cplex("filename.mps")
Model.parameters.optimalitytarget.set(float(3))
This worked for me!
Related
I want to use the bayesreg package within the MATLAB environment, which enables flexible Bayesian penalized regression modelling. I am following a paper, which details the software implementation within the MATLAB environment. I am using the exact instructions available in the paper but do not seem to get the code to work.
I have imported the table containing the data that I want to analyze. I then type the following code:
varnames=finale.Properties.VariableNames;
% count regression
X = finale{:,2:9}
y = finale{:,11}
[beta, beta0, retval] = bayesreg(X,y,'poisson','g','nsamples',1e5,'burnin',1e5,'thin',5,'displayor',true,'varnames',varnames(2:9),'display',true);
X and y are simply my dependent and independent variables, and all arguments of bayesreg are in agreement with the software implementation paper instructions.
I get the below error:
Undefined function or variable 'bayesreg'.
Could anyone shed any light?
In my case, the problem was that I didn't have the Neural Network toolbox installed, as well as another 1-2 packages. Installing those solved the issue.
The solution to Laplace PDE on rectangle is usually written using hyperbolic trig functions. I solve this PDE using Maple. Verified Maple solution is correct. But having hard time figuring how to make its result match the book result.
I tried sol:=convert(rhs(sol),trigh): then simplify(sol,trig); and it become little closer to the book solution, but is still can be more simplified.
Are there any tricks to do this?
Here is MWE
restart;
interface(showassumed=0):
pde:=diff(u(x,y),x$2)+diff(u(x,y),y$2)=0:
bc:=u(0,y)=0,u(a,y)=f(y),u(x,0)=0,u(x,b)=0:
sol:=pdsolve([pde,bc],u(x,y)) assuming(0<=x and x<=a and 0<=y and y<=b):
sol:=subs(infinity=20,sol);
Which gives
The above is same as the following, which I am trying to convert the above to
textbookU:= Sum(2*sin(n*Pi*y/b)*(Int(sin(n*Pi*y/b)*f(y),
y = 0 .. b))*sinh(n*Pi*x/b)/(b*sinh(n*Pi*a/b)), n = 1 .. 20);
The above are the same. I checked few points, and they give same answer. They must be the same, as the above textbook solution is correct, and I am assuming Maple solution is correct.
Now I tried to convert Maple sol to the above as follows
sol:=convert(rhs(sol),trigh):
simplify(sol,trig);
May be someone knows a better way to obtain the textbook solution form, starting from the Maple solution above.
Using Maple 2017.3 on windows
After the convert you can first expand it, to then simplify it again:
s := convert(sol, trigh):
s := expand(s):
simplify(s);
which gives:
Does anyone know how can I print the MIP logging on Matlab when calling AMPL from it? I'm using Gurobi as solver.
My Matlab code do:
system(['ampl.exe ' modelName.run]);
The modelName.run file has the AMPL code and calls Gurobi:
model model.md;
data input.dat;
option solver gurobi;
problem oampl: fo, constraints;
solve oampl;
The model.md has the objective function (fo) and the constraints.
I would like to see the log progress (initial solution, nodes, iterations, bounds etc.) of the MILP resolution process on Matlab. Should I do some parameter setting on Matlab or on AMPL? Or it can't be done?
When using Gurobi via AMPL the logging is turned off by default, you can turn it on with the following option:
option gurobi_options 'outlev 1' ;
More Details about the AMPL-Gurobi options can be found here:
http://www.gurobi.com/documentation/7.0/ampl-gurobi/parameters.html
I want to do a numerical integration of the following equation in Matlab.
For simplicity, lets pretend that only the second fraction of the equation is there.
And this is what I have tried so far:
for lambda=280:2500
numerator(lambda) = trapz(Einc(lambda:lambda+1)*St(lambda));
denominator(lambda) = trapz(Eref(lambda:lambda+1)*St(lambda));
end
Fraction= nansum(numerator)/ nansum(denominator);
St is not defined in the entire 280-2500 range, that is why I use nansum at the end. But overall I feel that what I’m doing is wrong and that there should be a much more normal and correct way of calculating this, yet I have tried googling this and asked on Mathworks forum as well but no one answers me even though this should be a pretty common thing to calculate… Could someone please help me how do write this formula?
I have few continuous variables that look like this:
durs1=[3,40933 0,033630 0,25103 0,6361 0,71971 1,18311 1,91946 0,12842 0,97639 1,1383 0,46871 3,05241 2,34907 1,03788 0,76434 1,08798 1,462 0,4241 2,32128 0,29017..]
Each has more than 1000 values (all positive). I used
[a, b]=gamfit(durs1)
a =
2.3812 0.4200
b =
2.2316 0.3907
2.5408 0.4514
to find parameters of gamma distribution. Now I want to make a goodness of fit test in order to see how well the model fits my data. Matlab provides the one sample Kolmogorov-Smirnov test to solve the problem (http://www.mathworks.com/help/stats/kstest.html#btnyrvz-1)
But when I run my code (based on their examples):
test_cdf=makedist('Gamma','a',2.38,'b',0.42)
[h, p]=kstest(durs1,'CDF',test_cdf)
I have this error: "Undefined function 'makedist' for input arguments of type 'char'."
Can somebody help me to fix my code?
It seems like the function makedist of the statistics toolbox is available only from Matlab version r2013a. Looking in the documentation of earlier versions, even as late as r2012b, there is no mention of makedist. So I think updating to the latest version of matlab should solve your problem.