How to optimise two variables at once

13 views (last 30 days)
Ryan Chung
Ryan Chung on 9 May 2021
Edited: Stephan on 10 May 2021
Hey, I'm trying to use the optimisation toolbox to find the lowest value for the massrms by using a range of values for b and c at the same time. Where 0<b<500 and 500<c<3000
I'm not exactly sure how to go about this wondering if someone could help as I have not used the toolbox before. I believe I have to use fmincon but not sure.
Thanks in advance
% Set up system matrices
b = 166; %inertance
c = 2000 %damping value
k = 28000; %suspension stiffness
kt = 160e3; %tyre stiffness
k1 = 8000 %2nd suspension stiffness
m = 50 %unsprung mass
M = (1850-4*m)/4 %(approx)sprung mass
Mmat = [M,0,0;0,b,-b;0,-b,m+b]; %mass matrix
Cmat = [c,-c,0;-c,c,0;0,0,0]; %damping matrix
Kmat = [k+k1,-k1,-k;-k1,k1+k1,-k1;-k,-k1,k+k1+kt]; %stiffness matrix
N = linspace(0.011,2.83,1000); %1000 wavenumbers in range as specified by ISO8608
V = 80000/3600; %vehicle speed in m/s
f = V*N; %array of corresponding temporal frequencies
w = 2*pi*f; %convert frequency from Hz to rad/s
T = zeros(length(f),3); %preallocate T to store transmission. at each freq
%Loop for each frequency
for i=1:length(f)
T(i,:) = inv(Kmat+(w(i)*j*Cmat)-((w(i)^2)*Mmat))*[0;0;kt];% transmissibility
end
n = 2; % waviness
C = 5E-6; % roughness
vref = 1; % reference wavenumber 1 cycle/m
PSDroadspatial = C*(N/vref).^(-n); % PSD in spatial frequency
PSDroadtemporal=PSDroadspatial/V; % PSD in temporal frequency
T=T'; % transpose T
PSDmass=abs(T(1,:)).^2 .* PSDroadtemporal;
PSDmass=PSDmass.*w.^4; % convert from displacement to acceleration PSD
df=f(2)-f(1); % Set frequency resolution (width of each frequency bin)
massrms = sqrt(sum(PSDmass)*df); % rms acceleration (sqrt of area under PSD graph)

Accepted Answer

Stephan
Stephan on 10 May 2021
Edited: Stephan on 10 May 2021
b = 166; %inertance
c = 2000; %damping value
lb = [0 500]; % lower bound
ub = [500 3000]; % upper bound
x0 = [b, c]; % initial values for optimization
[x,fval] = fmincon(@mySystem, x0, [], [], [], [], lb, ub)
function massrms = mySystem(x)
% Optimization variables
b = x(1);
c = x(2);
% Set up system matrices
k = 28000; %suspension stiffness
kt = 160e3; %tyre stiffness
k1 = 8000; %2nd suspension stiffness
m = 50; %unsprung mass
M = (1850-4*m)/4; %(approx)sprung mass
Mmat = [M,0,0;0,b,-b;0,-b,m+b]; %mass matrix
Cmat = [c,-c,0;-c,c,0;0,0,0]; %damping matrix
Kmat = [k+k1,-k1,-k;-k1,k1+k1,-k1;-k,-k1,k+k1+kt]; %stiffness matrix
N = linspace(0.011,2.83,1000); %1000 wavenumbers in range as specified by ISO8608
V = 80000/3600; %vehicle speed in m/s
f = V*N; %array of corresponding temporal frequencies
w = 2*pi*f; %convert frequency from Hz to rad/s
T = zeros(length(f),3); %preallocate T to store transmission. at each freq
%Loop for each frequency
for i=1:length(f)
T(i,:) = inv(Kmat+(w(i)*j*Cmat)-((w(i)^2)*Mmat))*[0;0;kt];% transmissibility
end
n = 2; % waviness
C = 5E-6; % roughness
vref = 1; % reference wavenumber 1 cycle/m
PSDroadspatial = C*(N/vref).^(-n); % PSD in spatial frequency
PSDroadtemporal=PSDroadspatial/V; % PSD in temporal frequency
T=T'; % transpose T
PSDmass=abs(T(1,:)).^2 .* PSDroadtemporal;
PSDmass=PSDmass.*w.^4; % convert from displacement to acceleration PSD
df=f(2)-f(1); % Set frequency resolution (width of each frequency bin)
massrms = sqrt(sum(PSDmass)*df); % rms acceleration (sqrt of area under PSD graph)
end
results in:
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>
x =
196.4737 536.3805
fval =
2.5596
  1 Comment
Ryan Chung
Ryan Chung on 10 May 2021
You're a life saver. Thanks so much!

Sign in to comment.

More Answers (0)

Categories

Find more on Problem-Based Optimization Setup 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!

Translated by