# How to set curve fitting bound as variabe?

2 views (last 30 days)
Joe Bennet on 23 Mar 2021
Commented: Lewis Marshall on 26 Mar 2021
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
Lewis Marshall on 24 Mar 2021
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.

Ananya Tewari on 26 Mar 2021
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] );
Lewis Marshall on 26 Mar 2021
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.

R2020b

### Community Treasure Hunt

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

Start Hunting!