Clear Filters
Clear Filters

Parameter optimization! Need Help!

2 views (last 30 days)
Daniel Valencia
Daniel Valencia on 20 Jan 2021
Commented: Daniel Valencia on 20 Jan 2021
Hello everyone,
I'm trying to optimizate some parameter by using the following function:
options=optimset('Algorithm','levenberg-Marquardt', 'LargeScale','off', 'DiffMaxChange',0.01, 'DiffMinChange',0.0001, 'TolFun',1e-5, 'TolX',0.001)
I already have the code and the optimization function complete, having the code starts from data which is read from an Excel book. Data is composed by two variables: strain and stress (two columns in the Excel book). I'm obtaining the results of the parameters successfully, but just from two variables in the mentioned Excel book, and I need to add another two (2), it is to say, I need to add more data to the same code in order to achieve more complete optimization results. It would be great if some of you can help me.
Here it is the code:
%% Optimization command
x0=[0.05, 1.2, 0.15]; %% Initial value of the parameters
% Vectors of lower and upper bounds on the design variables in x. Then, lb ? x ? ub
% For Levenberg-Marquardt algorithm use lb=[-inf] and ub=[inf]
lb=[0, 0, 0];
ub=[inf, inf, inf];
%lb=[0.1, 0.5];
%ub=[1, 1];
% optimization options:
options=optimset('Algorithm','levenberg-Marquardt', 'LargeScale','off', 'DiffMaxChange',0.01, 'DiffMinChange',0.0001, 'TolFun',1e-5, 'TolX',0.001);
[x,resnorm,residual,exitflag,output,lambda,jacobian]=lsqnonlin(@HSfun,x0,lb,ub,options);
%% Show Results and Optimization Details
dim=[1 1 1];
X=x.*dim;
resnorm;
exitflag;
output;
%% Read and plot observed data
Labdata=dlmread('C:\Hypoplastic Model Optimisation\Labdata.csv');
strain=Labdata(:,1);
qobserved=Labdata(:,2);
plot(strain,qobserved,'rx')
hold on
%% Read and plot calculated data
CalculatedData=xlsread('C:\Hypoplastic Model Optimisation\CalculatedData.xls');
strain=CalculatedData(:,1)*-100; % strain in percentage
qcalculated=CalculatedData(:,2);
plot(strain,qcalculated)
The script counts with an auxiliary function which is the one that really makes the optimization process:
%% Read observed data
Labdata=dlmread('C:\Hypoplastic Model Optimisation\Labdata.csv');
strain=Labdata(:,1);
qobserved=Labdata(:,2);
%% Calculated values
X=x.*dim;
u=X(1);
X1=X(2);
br=X(3);
%%%%%%% write parameters in files !!THIS DOES NOT MATTER FOR MATLAB COMMUNITY WHO ARE READING!!
dlmwrite('C:\Hypoplastic Model Optimisation\u.txt',u,'newline','pc','precision','%15.10f');
dlmwrite('C:\Hypoplastic Model Optimisation\X1.txt',X1,'newline','pc','precision','%15.10f');
dlmwrite('C:\Hypoplastic Model Optimisation\Br.txt',br,'newline','pc','precision','%15.10f');
%%% Macro to write parameters into PLAXIS project ! THIS DOES NOT MATTER FOR MATLAB COMMUNITY WHO ARE READING!!
!C:\Hypoplastic Model Optimisation\WriteParameters.exe
%%% Macro to run PLAXIS and extract calculated data into CalculatedData.xls file !!THIS DOES NOT MATTER FOR MATLAB COMMUNITY WHO ARE READING!!
!C:\Hypoplastic Model Optimisation\RunPlaxis.exe
%% Read Calculated raw data from CalculatedData.xls file
CalculatedData=xlsread('C:\Hypoplastic Model Optimisation\CalculatedData.xls');
strainraw=CalculatedData(:,1)*-100; % strain in percentage
qcalculatedraw=CalculatedData(:,2);
%%% Interpolate Calculated data to get values at same strain as observed data
strain_transp = transpose(strain); % sames strain values as observed data
qcalculated = interp1(strainraw,qcalculatedraw,strain_transp,'spline');
%% calculate the difference between observed and calculated response
F=qobserved-qcalculated';
end
I know this might be not so clear, but if somebody wanna help a suffering soul, thanks in advance.
  4 Comments
ziyue zhong
ziyue zhong on 20 Jan 2021
sorry,but I don't really understand what your trouble is...What is your optimise function?What's the relation between varibles(strain etc) and x?
Daniel Valencia
Daniel Valencia on 20 Jan 2021
Sorry about this, I'll try to explain it clearly.
I have some laboratory data (LabData) and Calculated data (from other software). Laboratory and calculated data are both composed by strain and stress information, shown in columns in Excel books.
My code takes the information of the labroatory data (which is really a curve: Strain vs Stress) and compare it with the calculated one, iterating the parameters and reducting the error (optimizating).
At the end, i succesfully get the resulting optimizated parameters, but the whole process considers only 1 CURVE OF DATA (Strain vs Stress), and I need to add another 2 curves to the script (composed by two columns: strain and stress each), in orther to have the optimization considers the 3 curves instead of inly one!
I don't know how to add the other curves, I allways have errors and script does not run.

Sign in to comment.

Answers (0)

Categories

Find more on Stress and Strain in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!