How to set curve fitting bound as variabe?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Lewis Marshall
el 24 de Mzo. de 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.
Respuestas (1)
Ananya Tewari
el 26 de Mzo. de 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] );
1 comentario
Lewis Marshall
el 26 de Mzo. de 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.
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!