Encountering error with using fmincon
11 views (last 30 days)
Show older comments
I have the following experimental data (attached xlsx file). I am trying to fit the experimental stress data, which are denoted by predicted_experimentalstress, to the analytical equivalent (Gent model) where the Filled_stretchextensometer represents the corresponding stretch data.
clear all
close all
clc
data = xlsread('C:\Users\me-admin\Videos\Daniela\Fresh_5\Fresh5_data.xlsx');
strain_extensometer= data((3:268),3);
time_DIC= data((3:268),2);
experimentalstress_original= data((3:667),7);
time_utm= data((3:667),4);
[F,TF] = fillmissing(strain_extensometer,'linear','SamplePoints',time_DIC);
Filled_stretchextensometer= F+1;
hold on
predicted_experimentalstress= interp1(time_utm,experimentalstress_original,time_DIC,"linear","extrap");
figure;
J = @(x,Filled_stretchextensometer) ((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2)))./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3)));
residue_function = @(x) sum((((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2)))./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3))) - predicted_experimentalstress).^2);
x0 = [33, 0.2];
gs = GlobalSearch;
problem = createOptimProblem('fmincon', 'x0', x0,'objective', residue_function);
x = run(gs,problem)
lb = [];
ub = [];
fprintf(['The value of x(1)%f.\n'],x(1));
fprintf([ 'The value of x(2)%f.\n'],x(2));
fprintf(['The value of resnorm %f.\n'], resnorm);
times = linspace(Filled_stretchextensometer(3),Filled_stretchextensometer(end));
plot(Filled_stretchextensometer, predicted_experimentalstress, times, J(x, times), 'r-');
legend('Experiment', 'Fitted curve(Gent Model)');
title('Fresh 5');
xlabel('Stretch');
ylabel('Engineering Stress (KPa)');
I am attempting to use the fmincon function in the follwing script with an additional constraint that parameter x(2) > 0, but I am encountering an error. How may I resolve this? I am unable to include the constraint within the optimization.
0 Comments
Accepted Answer
Walter Roberson
on 7 Sep 2023
Edited: Walter Roberson
on 7 Sep 2023
format long g
data = xlsread('Fresh5_Data.xlsx');
strain_extensometer= data((3:268),3);
time_DIC= data((3:268),2);
experimentalstress_original= data((3:667),7);
time_utm= data((3:667),4);
[F,TF] = fillmissing(strain_extensometer,'linear','SamplePoints',time_DIC);
Filled_stretchextensometer= F+1;
hold on
predicted_experimentalstress= interp1(time_utm,experimentalstress_original,time_DIC,"linear","extrap");
figure;
J = @(x,Filled_stretchextensometer) ((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2)))./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3)));
residue_function = @(x) sum((((x(1).*x(2)*(Filled_stretchextensometer-(1./Filled_stretchextensometer.^2)))./(x(2)-(Filled_stretchextensometer.^2+(2./Filled_stretchextensometer)-3))) - predicted_experimentalstress).^2);
x0 = [33, 0.2];
gs = GlobalSearch;
problem = createOptimProblem('fmincon', 'x0', x0, 'objective', residue_function, 'lb', [-inf 0]);
[x, resnorm] = run(gs,problem)
lb = [];
ub = [];
fprintf(['The value of x(1) %f.\n'],x(1));
fprintf([ 'The value of x(2) %f.\n'],x(2));
fprintf(['The value of resnorm %f.\n'], resnorm);
times = linspace(Filled_stretchextensometer(3),Filled_stretchextensometer(end));
plot(Filled_stretchextensometer, predicted_experimentalstress, times, J(x, times), 'r-');
legend('Experiment', 'Fitted curve(Gent Model)');
title('Fresh 5');
xlabel('Stretch');
ylabel('Engineering Stress (KPa)');
0 Comments
More Answers (0)
See Also
Categories
Find more on Stress and Strain 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!
