Encountering error with using lsqcurvefit

6 次查看(过去 30 天)
I have the following experimental data.
xdata = [1 1.01 1.12 1.24 1.39 1.61 1.89 2.17 2.42 3.01 3.58 4.03 4.76 5.36 5.76 6.16 6.40 6.62 6.87 7.05 7.16 7.27 7.43 7.50 7.61];
ydata = [0 0.03 0.14 0.23 0.32 0.41 0.50 0.58 0.67 0.85 1.04 1.21 1.58 1.94 2.29 2.67 3.02 3.39 3.75 4.12 4.47 4.85 5.21 5.57 6.30];
I am trying to fit the ydata, which are stresses denoted by P, to the analytical equivalent (see equation) where the xdata represents the corresponding strains denoted by λ.
I am attempting to use the lsqcurvefit function in the follwing script but I am encountering an error. How may I resolve this? I am unfamiliar with most of the information returned to me
clear all
close all
clc
% xdata (Stretch, Lamda)
xdata = [1 1.01 1.12 1.24 1.39 1.61 1.89 2.17 2.42 3.01 3.58 4.03 4.76 5.36 5.76 6.16 6.40 6.62 6.87 7.05 7.16 7.27 7.43 7.50 7.61];
% ydata (Nominal Stress, P)
ydata = [0 0.03 0.14 0.23 0.32 0.41 0.50 0.58 0.67 0.85 1.04 1.21 1.58 1.94 2.29 2.67 3.02 3.39 3.75 4.12 4.47 4.85 5.21 5.57 6.30];
% Proposition
% ydata = (a*b*xdata^3 - 1))/(xdata)*(xdata*b - xdata^3 + 3*xdata - 2));
% Gent Model Y-Axis
gent_function = @(x,xdata)(x(1)*x(2)*(xdata^3 - 1))/((xdata)*(xdata*x(2) - xdata^3 + 3*xdata - 2));
% Fit Model w/ Start
x0 = [100, 0.1];
x = lsqcurvefit(gent_function,x0,xdata,ydata);
% Plot Data & Fitted Curve
times = linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,gent_function(x,times),'b-')
legend('Data','Fitted Exponential')
title('Data and Fitted Curve')
--------------------------------------------------------------------------------------------------
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a
power. Check that the matrix is square and the power
is a scalar. To perform elementwise matrix powers,
use '.^'.
Error in
check>@(x,xdata)(x(1)*x(2)*(xdata^3-1))/((xdata)*(xdata*x(2)-xdata^3+3*xdata-2))
(line 15)
gent_function = @(x,xdata)(x(1)*x(2)*(xdata^3 -
1))/((xdata)*(xdata*x(2) - xdata^3 + 3*xdata - 2));
Error in lsqcurvefit (line 225)
initVals.F =
feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in check (line 19)
x = lsqcurvefit(gent_function,x0,xdata,ydata);
Caused by:
Failure in initial objective function
evaluation. LSQCURVEFIT cannot continue.

采纳的回答

Walter Roberson
Walter Roberson 2021-1-8
% xdata (Stretch, Lamda)
xdata = [1 1.01 1.12 1.24 1.39 1.61 1.89 2.17 2.42 3.01 3.58 4.03 4.76 5.36 5.76 6.16 6.40 6.62 6.87 7.05 7.16 7.27 7.43 7.50 7.61];
% ydata (Nominal Stress, P)
ydata = [0 0.03 0.14 0.23 0.32 0.41 0.50 0.58 0.67 0.85 1.04 1.21 1.58 1.94 2.29 2.67 3.02 3.39 3.75 4.12 4.47 4.85 5.21 5.57 6.30];
% Proposition
% ydata = (a*b*xdata^3 - 1))/(xdata)*(xdata*b - xdata^3 + 3*xdata - 2));
% Gent Model Y-Axis
gent_function = @(x,xdata)(x(1)*x(2)*(xdata.^3 - 1))./((xdata).*(xdata*x(2) - xdata.^3 + 3*xdata - 2));
% Fit Model w/ Start
x0 = [100, 0.1];
x = lsqcurvefit(gent_function,x0,xdata,ydata);
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
% Plot Data & Fitted Curve
times = linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,gent_function(x,times),'b-')
legend('Data','Fitted Exponential')
title('Data and Fitted Curve')
  3 个评论
Walter Roberson
Walter Roberson 2021-1-8
% xdata (Stretch, Lamda)
xdata = [1 1.01 1.12 1.24 1.39 1.61 1.89 2.17 2.42 3.01 3.58 4.03 4.76 5.36 5.76 6.16 6.40 6.62 6.87 7.05 7.16 7.27 7.43 7.50 7.61];
% ydata (Nominal Stress, P)
ydata = [0 0.03 0.14 0.23 0.32 0.41 0.50 0.58 0.67 0.85 1.04 1.21 1.58 1.94 2.29 2.67 3.02 3.39 3.75 4.12 4.47 4.85 5.21 5.57 6.30];
% Proposition
% ydata = (a*b*xdata^3 - 1))/(xdata)*(xdata*b - xdata^3 + 3*xdata - 2));
% Gent Model Y-Axis
gent_function = @(x,xdata)(x(1)*x(2)*(xdata.^3 - 1))./((xdata).*(xdata*x(2) - xdata.^3 + 3*xdata - 2));
residue_function = @(x) sum(((x(1)*x(2)*(xdata.^3 - 1))./((xdata).*(xdata*x(2) - xdata.^3 + 3*xdata - 2)) - ydata).^2);
% Fit Model w/ Start
x0 = [100, 0.1];
gs = GlobalSearch;
problem = createOptimProblem('fmincon', 'x0', x0, ...
'objective', residue_function);
x = run(gs,problem)
GlobalSearch stopped because it analyzed all the trial points. All 8 local solver runs converged with a positive local solver exit flag.
x = 1×2
0.2451 79.4367
% Plot Data & Fitted Curve
times = linspace(xdata(1),xdata(end));
plot(xdata,ydata,'ko',times,gent_function(x,times),'b-')
legend('Data','Fitted Exponential')
title('Data and Fitted Curve')
Joshua Rees
Joshua Rees 2021-1-11
Hello,
Thanks for your time and helping out. I think the first solution you posted is correct, by running the amended script I can now produce a graph (which is similar if not the same to the graph in the third solution).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by