how do I turn a piece of code into a parametric optimisation

4 次查看(过去 30 天)
I have a piece of code that I would like to turn into a parametric optimisation
clear
close all
%
% Matrix properties (8552 example)
Em = 380E3; % Young's modulus
num = 0.22; % Poisson's ratio
Vv = 0.01;
KIc = 3.63; % MPa*sqrt(m) fracture toughness
% Dv = 1E-3; % void diameter
%
% Crack density parameter (from Budiansky and O'Connel, IJSS 12:81-97, 1976)
cdp0 = 0;
cdp = cdp0;
a = 0.01;
%
%%
% MECHANISMS OF CYCLIC FATIGUE-CRACK PROPAGATION IN A FINE-GRAINED ALUMINA
% CERAMIC: THE ROLE OF CRACK CLOSURE C. J. Gilbert, R. O. Ritchie 2008
C = 1.3E-18; % Paris law coefficient
m = 23; % material exponent
%
%%
% some code goes here
for k = 1:N_cycles
% some code goes here
end
I would like to change the variables Vv between 0.01, 0.38, and 0.47. I woul like to then be able to optimise a, C, and m so I can determine when these numbers give me the closest to arbitray values from literature.
Thanks
Alex

采纳的回答

Walter Roberson
Walter Roberson 2023-6-5
%
% Matrix properties (8552 example)
Em = 380E3; % Young's modulus
num = 0.22; % Poisson's ratio
Vv_vals = [0.01, 0.38, 0.47];
KIc = 3.63; % MPa*sqrt(m) fracture toughness
% Dv = 1E-3; % void diameter
%
% Crack density parameter (from Budiansky and O'Connel, IJSS 12:81-97, 1976)
cdp0 = 0;
cdp = cdp0;
a = 0.01;
%
%%
% MECHANISMS OF CYCLIC FATIGUE-CRACK PROPAGATION IN A FINE-GRAINED ALUMINA
% CERAMIC: THE ROLE OF CRACK CLOSURE C. J. Gilbert, R. O. Ritchie 2008
C = 1.3E-18; % Paris law coefficient
m = 23; % material exponent
%
%%
num_Vv = length(Vv_vals);
for Vv_idx = 1 : num_Vv
Vv = Vv_vals(Vv_idx);
% some code goes here
for k = 1:N_cycles
% some code goes here
end
results_per_Vv(Vv_idx) = appropriate per-Vv result
end
  2 个评论
Walter Roberson
Walter Roberson 2023-6-5
Yes. Use a vector of actual values for each of them, and calculate length of the vector, and iterate 1 to length of the vector, extract the relevant value from the full list, and use the iteration index to index where to store results.
Note: it is advisable to pre-allocate the output variables; use the recorded lengths of the vectors to size the output variables.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by