Encountering error with using lsqcurvefit
조회 수: 2 (최근 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.
댓글 수: 0
채택된 답변
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);
% 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
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)
% 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')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!