Function optimization meeting some conditions
Show older comments
I have a array ht(i,j) and i want to calculate de values that minimize de sumatory of sum((hti,j)-h(j).^2), meeting the conditions: h(j)<120, h(j+1)>h(j) and h(j+1)-h(j)<1.25. I am trying doing it with the optimizetool but i don´t know how, and using fmincon i have done this:
function [h] = hp3(ht)
[n,m]=size(ht);
Ins = @(h) sum((ht - h).^2);
h0 = zeros(size(m));
A = [];
b = [];
Aeq = [];
beq = [];
lb = [];
ub = [];
h = fmincon(Ins, h0, A, b, Aeq, beq, lb, ub, @constraints);
end
function [c, ceq] = constraints(h)
c = h(2:end) - h(1:end-1);
ceq = [];
end
1 Comment
Jon
on 8 Jun 2023
Also your line of code:
h0 = zeros(size(m));
Doesn't look correct, m is a scalar so size(m) will by 1,1
I think you want
h0 = zeros(m,1);
Accepted Answer
More Answers (0)
Categories
Find more on Surrogate Optimization 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!