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

조회 수: 1 (최근 30일)
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

채택된 답변

Torsten
Torsten 2024년 5월 1일
[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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by