minimum value of one inequality
Show older comments
i need to calculate n which should give minimum even value from the expression. what function should i use to code this.
1/(2^(n/2)) + (r/s)*(1 - 1/(2^(n/2)))<=0.1
if the value of r is known (say=0.001) and s=7;
then if i calculate manually i am getting n>=6.64
but i need minumum even integer so i should get n=8.
want to know how to code these kind of inequality
p.s: i am a beginner
Accepted Answer
More Answers (1)
Ameer Hamza
on 24 Sep 2020
One way is to use optimization toolbox
fmincon(@(n) n, 0, [], [], [], [], [], [], @nlcon)
function [c, ceq] = nlcon(n)
r = 0.001;
s = 7;
c = 1/(2^(n/2)) + (r/s)*(1 - 1/(2^(n/2))) - 0.05;
ceq = [];
end
4 Comments
danish ansari
on 24 Sep 2020
Bruno Luong
on 24 Sep 2020
fmincon is not applicable for integer optimization.
John D'Errico
on 24 Sep 2020
GA would work.
Ameer Hamza
on 24 Sep 2020
Oh! I missed the part about the solution being an integer. Yes, ga() will work here.
n = ga(@(n) n, 1, [], [], [], [], [], [], @nlcon, 1);
function [c, ceq] = nlcon(n)
r = 0.001;
s = 7;
c = 1/(2^(n/2)) + (r/s)*(1 - 1/(2^(n/2))) - 0.05;
ceq = [];
end
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!