# Learn Optimization Techniques with MATLAB

9 views (last 30 days)
Donne on 7 Feb 2024
Commented: Donne on 8 Feb 2024
I'm facing a significant challenge with an assignment that has been ongoing for some time. After considerable effort, I believe that incorporating MATLAB could provide the most effective solution. However, the problem involves non-linear, constrained, and multi-objective optimization, which requires a graphical approach. Unfortunately, despite extensive online research and video tutorials, I haven't found resources specifically addressing this scenario. Most materials seem to focus on linear programming problems or utilize MATLAB's optimization toolbox, which doesn't align with the unique demands of my assignment.
I would be immensely grateful for any guidance on relevant resources that could assist me in solving and learning about this approach. Furthermore, I would be incredibly appreciative of mentorship from someone willing to teach me advanced engineering problem-solving techniques using MATLAB. While not directly related to the problem itself, I wanted to share the complexity in the image below I'm facing to provide context.
Thank you for your time and consideration.
Donne on 8 Feb 2024
So this is the actual problem I am facing. I have been able to partly solve my problem. The issue is that, I am not getting the graph I want.
`% this is to solve the optimization of a two two-bar truss system
close all; clear; clc
%% DEFINED SCALAR PARAMETERS
Aref = 1; %in^2
E = 30 * 10^6;%psi
rho = 0.283;%lb/in^3
P = 10000;%lb
sigma_0= 20000;%psi
h = 100;%in
%% DEFINED PHYSICAL CONSTRAINTS
x1 = linspace(0.1,2.0,1000);
x2 = linspace(0.1,2.5,10000);
[X, Y] = meshgrid(x1, x2);
%% DEFINED OBJECTIVE functions
% Objective function for the weight
obj_fun_1 = 2*( rho * h .* Y .* sqrt((1 + X.^2)) .* Aref) - 0.5;
%Objective function for the displacement of truss beams
obj_fun_2 = P * h *(1+X.^2).^1.5 .*sqrt((1 + X.^4)) ./ ...
(2*sqrt(2)*E .*X.*Y*Aref) - 0.5;
%% PERFORMANCE CONSTRAINTS
% Constraint 1
con_fun_1 = (P * (1 + X).*sqrt((1 + X.^2)))./(2*(sqrt(2))*X.*Y*Aref) <= sigma_0;
% Constraint 2
con_fun_2 = (P * (1 - X).*sqrt((1 + X.^2)))./(2*(sqrt(2))*X.*Y*Aref) <= sigma_0;
%% Question 1a
figure('Name','Objective Function 1')
contour(X,Y, obj_fun_1,1)
hold on
contour(X,Y, con_fun_1,1)
contour(X,Y, con_fun_2,1)
hold off
%% Question 1b
figure('Name','Objective Function 2')
contour(X,Y, obj_fun_2,1)
hold on
contour(X,Y, con_fun_1,1)
contour(X,Y, con_fun_2,1)
hold off
%% Question 1c
obj_fun_combined =obj_fun_2 + obj_fun_2;
figure('Name','Objective Functions Combined')
contour(X,Y, obj_fun_combined,1)
hold on
contour(X,Y, con_fun_1,1)
contour(X,Y, con_fun_2,1)
hold off
`
the obj_fun_1 is supposed to plot the curve in blue, and when you change the constant, i.e -0.5 of the equation, it should make the mulitple plots. But i am getting something way off. And what i understand is that as change the value of the constant the position of the curve of the obj_fun_1 should also be changing but my code is not updating the position of the code even when I change the code. I really need help

Sam Chak on 7 Feb 2024
Edited: Sam Chak on 7 Feb 2024
If this is indeed a static optimization problem, the minimization of the volume of the cone clutch can be achieved by first deriving an equation that describes the volume (V) as a cost function of the outer and inner radii, denoted as . For constrained nonlinear bi-variate function like your case, you can use fmincon() to solve the problem.
Vol = @(R) 100*(R(2) - R(1)^2)^2 + (1 - R(1))^2; % <-- this is the Cost function
R0 = [7.5 5]; % initial guess: R(1) = 7.5, & R(2) = 5
lb = [ 0 0]; % lower bound of R(1) = 0 and R(2) = 0
ub = [15 10]; % upper bound of R(1) = 15 and R(2) = 10
opt = optimset('Display', 'iter', 'PlotFcns', @optimplotfval);
[R, fval, exitflag, output] = fmincon(Vol, R0, [], [], [], [], lb, ub, [], opt)
First-order Norm of Iter F-count f(x) Feasibility optimality step 0 3 2.626985e+05 0.000e+00 1.511e+05 1 6 5.301462e+03 0.000e+00 2.751e+03 7.804e+00 2 9 1.134062e+03 0.000e+00 2.642e+03 3.916e+00 3 12 1.027922e+00 0.000e+00 1.951e+03 3.349e+00 4 15 1.085873e+00 0.000e+00 1.174e+01 1.256e-02 5 18 1.032356e+00 0.000e+00 2.268e+00 1.198e-02 6 22 8.614146e-01 0.000e+00 3.390e+00 6.447e-02 7 25 7.444495e-01 0.000e+00 5.582e+00 6.463e-02 8 29 8.549904e-01 0.000e+00 1.558e+01 1.593e-01 9 32 6.027884e-01 0.000e+00 3.348e+00 7.036e-02 10 35 5.274331e-01 0.000e+00 2.398e+00 5.454e-02 11 38 4.351649e-01 0.000e+00 6.432e+00 1.671e-01 12 41 3.235134e-01 0.000e+00 3.622e+00 5.931e-02 13 44 2.444178e-01 0.000e+00 5.693e+00 1.853e-01 14 47 1.181306e-01 0.000e+00 3.392e+00 1.553e-01 15 51 6.780342e-02 0.000e+00 2.489e+00 1.419e-01 16 54 7.008936e-02 0.000e+00 6.057e+00 1.125e-01 17 57 3.162683e-02 0.000e+00 2.629e+00 5.293e-02 18 60 1.246636e-02 0.000e+00 2.824e+00 1.621e-01 19 63 8.402327e-04 0.000e+00 4.321e-01 1.107e-01 20 67 5.741135e-03 0.000e+00 2.906e+00 1.016e-01 21 70 3.304907e-03 0.000e+00 1.244e+00 6.478e-02 22 73 7.531599e-03 0.000e+00 1.044e+00 8.200e-02 23 76 1.004160e-02 0.000e+00 8.230e-01 3.780e-02 24 79 1.469296e-02 0.000e+00 4.367e-01 5.381e-02 25 82 1.322302e-02 0.000e+00 8.969e-02 1.410e-02 26 85 3.862072e-03 0.000e+00 9.063e-01 1.369e-01 27 88 2.164421e-03 0.000e+00 6.908e-01 3.482e-02 28 91 1.247162e-03 0.000e+00 2.624e-01 1.869e-02 29 94 6.295441e-04 0.000e+00 9.372e-02 2.245e-02 30 97 7.078191e-04 0.000e+00 1.948e-02 3.741e-03 First-order Norm of Iter F-count f(x) Feasibility optimality step 31 100 1.068763e-04 0.000e+00 1.841e-01 3.974e-02 32 103 4.429148e-05 0.000e+00 4.264e-02 5.854e-03 33 106 3.002993e-05 0.000e+00 3.978e-03 2.289e-03 34 109 8.728886e-07 0.000e+00 2.631e-02 1.102e-02 35 112 1.228581e-06 0.000e+00 1.990e-03 1.212e-03 36 115 1.161267e-06 0.000e+00 7.991e-04 6.726e-05 37 118 5.092558e-08 0.000e+00 6.126e-04 1.909e-03 38 121 4.503264e-08 0.000e+00 1.600e-04 2.877e-05 39 124 1.018006e-11 0.000e+00 4.570e-05 4.817e-04 40 127 5.337221e-12 0.000e+00 1.600e-06 1.570e-06 Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
R = 1×2
1.0000 1.0000
fval = 5.3372e-12
exitflag = 2
output = struct with fields:
iterations: 41 funcCount: 148 constrviolation: 0 stepsize: 7.3289e-11 algorithm: 'interior-point' firstorderopt: 1.6000e-06 cgiterations: 25 message: 'Local minimum possible. Constraints satisfied.↵↵fmincon stopped because the size of the current step is less than↵the value of the step size tolerance and constraints are ↵satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the relative changes in all elements of x are↵less than options.StepTolerance = 1.000000e-10, and the relative maximum constraint↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-06.' bestfeasible: [1×1 struct]
Donne on 7 Feb 2024
Thank you

### Categories

Find more on Get Started with Optimization Toolbox 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!