Error using fmincon and integral: taking integral variable as an array while performing computation

5 views (last 30 days)
I am minimizing q for whole range of p from 2 to 20, to find the value of d, r_g,G_g. q is function of p,d, r_g, G_g.
But while computation p is behaving as an array values varing from 2 to 20. Because of this I am getting error. How to correct this. Here my part of code
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset('PlotFcns', @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral(@(p)q(p,x(1),x(2),x(3)),2*pi,20*pi),d0,[],[],[],[],lb,ub,[],options); % minimize q for full range of p
function q = optimizeParameters()
% syms p d r_g G_g
%p = 2*pi;
theta = pi/4;
Vs = 250;
k = @(p)p/Vs;
c = Vs/sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d - d;
q = @(p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
p % printing the p here which is giving an array because of this error in further computation
% rest of the code
end

Accepted Answer

Torsten
Torsten on 1 May 2024
[q] = optimizeParameters();% Call optimizeParameters to define the objective function q
options = optimset('PlotFcns', @optimplotfval);% Set optimization options
d0 = [-0.5, 24, 3e6];
lb = [-1, 24, 2e6];
ub = [0, 32, 6e6];
[solution,fval] = fmincon(@(x)integral(@(p)q(p,x(1),x(2),x(3)),2*pi,20*pi,'ArrayValued',true),d0,[],[],[],[],lb,ub,[],options); % minimize q for full range of p
function q = optimizeParameters()
% syms p d r_g G_g
%p = 2*pi;
theta = pi/4;
Vs = 250;
k = @(p)p/Vs;
c = Vs/sin(theta);
w5 = 0.001;
n = 3;
dl = -6;
d1 = @(d)dl + 2 * n * d - d;
q = @(p, d, r_g, G_g) calculateObjective(theta, p, d, r_g, G_g, Vs, k(p), c, w5, n, dl, d1(d));
end
function answer = calculateObjective(theta, p, d, r_g, G_g, Vs, k, c, w5, n, dl, d1);
p % printing the p here which is giving an array because of this error in further computation
% rest of the code
end

More Answers (0)

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!