How to set curve fitting bound as variabe?

3 次查看(过去 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
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
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
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 CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by