Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Incorrect answers/calling of variables in constraint optimization

조회 수: 1 (최근 30일)
Hadi Ahmed
Hadi Ahmed 2020년 3월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
S=assignstudent(1824283); P=25*(1+(0.1*S)); E=2; h=2;
lb = [0.2; 0.2*(1-(0.1*S))]; %Defining the lower bounds of the constraint
ub = [6*(1+(0.2*S)); 6]; %Defining the upper bounds of the constraint
x0 = [2;1.8]; %Initial guess
opts=optimset('Display','iter','Algorithm','sqp');
%Options to define the characteristics of function fmincon
[x,fm]=fmincon(@(x)p2(x,P,h,E),x0,[],[],[],[],lb,ub,@(x)p2constraints(x,P,S),opts);
%Using fmincon to find a solution
fprintf('The optimal value for A1 is %g m^2 \n' ,x(1))
fprintf('The optimal value for A2 is %g m^2 \n',x(2))
fprintf('The minimum vertical deflection at the loaded joint is %g metres \n',fm)
x1opt=x(1); x2opt=x(2);
function f=p2(x, P, h, E)
%Objective Function for vertical deflection at loaded joint
f=((P*h)/E)*(1/(x(1)+sqrt(2)*x(2)));
end
function [c, ceq]=p2constraints(x, P, S)
%Cost function to describe the constraints
c=[P*((x(2)+sqrt(2)*x(1))/(sqrt(2)*x(1)^2+2*x(1)*x(2)))-17.5*(1+(0.1*S));
P*(1/(x(1)+sqrt(2)*x(1)))-17.5*(1+(0.1*S));
P*(x(2)/(sqrt(2)*x(1)^2+2*x(1)*x(2)))-1.2];
%Non-linear inequality constraint expressions, each element represents
%a constraint
ceq=[]; %No non-linear constraing, therefore this is equal to zero
end
The code above gives me the following
Iter Func-count Fval Feasibility Step Length Norm of First-order
step optimality
0 3 6.032261e+00 2.639e+00 1.000e+00 0.000e+00 1.877e+00
1 6 3.169880e+00 1.061e+00 1.000e+00 2.382e+00 4.960e-01
2 9 2.532267e+00 3.216e-01 1.000e+00 1.474e+00 3.165e-01
3 12 2.140984e+00 5.579e-02 1.000e+00 1.206e+00 2.233e-01
4 15 1.753657e+00 0.000e+00 1.000e+00 1.681e+00 1.586e-01
5 18 1.752427e+00 0.000e+00 1.000e+00 7.756e-03 3.822e-03
6 21 1.752427e+00 0.000e+00 1.000e+00 0.000e+00 0.000e+00
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
The optimal value for A1 is 7.16167 m^2
The optimal value for A2 is 6 m^2
The minimum vertical deflection at the loaded joint is 1.75243 metres
The values for A1 and A2 are incorrect. It keeps returning the upper bound as for the values of A1 and A2, respectively. Not sure what the problem is, but I'm not getting the minimal values for A1 and A2.

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by