How to set curve fitting bound as variabe?
조회 수: 5 (최근 30일)
이전 댓글 표시
hello i am trying to curve fit a set of data to the equation y=-(c10 + c01/x)*(2/x - 2*x^2) where c01>0 and c01+c10>0, i generated this code from the curve fitting toolbx and have been implementing it in a loop for a number of other data sets, how do i implement the lower bound for c10 > -c01?
please find attached code, thank you
clc
clear
[xData, yData] = prepareCurveData( x1, y1 );
% Set up fittype and options.
ft = fittype( '-(c10 + c01/x)*(2/x - 2*x^2)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares','Lower',[0,0] );
names=coeffnames(ft)
opts.Display = 'Off';
opts.StartPoint = [0.421761282626275 0.8002804688888];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
coefficientvalues(1,:)=coeffvalues(fitresult)
txt = ['Sample ',num2str((1))]
t={'c01 = ' num2str(coefficientvalues(1,1)),'c10 = ' num2str(coefficientvalues(1,2))}
% Plot fit with data.
hold on
h = plot( fitresult, xData, yData );
legend( h, txt, 'mooney2', 'Location', 'NorthEast', 'Interpreter', 'none' );
text(1.1,2E5,t)
% Label axes
xlabel( '\lambda');
ylabel( '\sigma_{m}');
grid on
댓글 수: 1
Lewis Marshall
2021년 3월 24일
I have also been having a similar issue where my coefficient values are interdependent. If anybody knows how to set this in the bounds in the curve fitting toolbox it would be greatly appreciated.
답변 (1개)
Ananya Tewari
2021년 3월 26일
I understand you want to set the curve fitting bounds as a variable. A workaround to satisfy the above condition c01 + c10 > 0 we can consider c10 to be extremely small positive number say 10^-10 and set that as lower bound. This will keep the condition in check while curve fitting. Here is the code for the same.
opts = fitoptions( 'Method', 'NonlinearLeastSquares','Lower',[0, 10^-10] );
댓글 수: 1
Lewis Marshall
2021년 3월 26일
thank you for getting back to me, unfortuantely this will not work as c10 should ideally be a negative number, it should however be large enough ( close enough to 0) that the sum of c01 and c10 is greater than 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!