Curve fit not spanning the whole data set
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have the following datasets:
L=1;
D=2*0.02;
V1=[0.00010, 0.00025, 0.00050, 0.00075, 0.00100, 0.00250, 0.00500, 0.00750];
V2=[0.01, 0.10, 0.50, 1.00, 3.00, 5.00, 7.00, 10.00];
V=[V1, V2];
Re=(1000*V*D)/(0.001);
lambda_E=(p*D)./(0.5*1000*L*V.^2);
lambda_HP=64./Re;
lambda_W=1.02*(log10(Re)).^(-2.5);
I want to draw a curve over these points, so I fitted them, using the Curve Fitting Toolbox, to a custom equation, that being: a*(log10(x)).^(-2.5), where 'a' is a coefficient. If there's any other way to create a smooth line that goes over these points please let me know about it. I then exported the corresponding code to a function I'd made earlier. Said code looks as follows:
[xData, yData] = prepareCurveData( Re, lambda_W );
% Set up fittype and options.
ft = fittype( 'a*(log10(x)).^(-2.5)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonLinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = 1.02;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
plot( Re, lambda_W, 'o', MarkerSize=3, MarkerFaceColor='k', MarkerEdgeColor='k' );
h = plot( fitresult );
set(h,LineWidth=1.3,Color='r');
However, when I run the original program in which I use the function, the curve I just mentioned (colored red in the picture) stops past a certain value of the 'Re' axis:

This is the full code of the program and the function, respectively:
L = 1;
D = 2*0.02;
V1 = [ 0.00010, 0.00025, 0.00050, 0.00075, 0.00100, 0.00250, 0.00500, 0.00750 ];
V2 = [ 0.01, 0.10, 0.50, 1.00, 3.00, 5.00, 7.00, 10.00 ];
V = [ V1, V2 ];
logV = log( V );
p1 = [ 0.00247, 0.00619, 0.01250, 0.01890, 0.02550, 0.06770, 0.14800, 0.24000 ];
p2 = [ 0.3400, 8.6500, 116.2070, 370.3552, 2442.9590, 5996.8000, 10924.6200, 21040.5100 ];
p = [ p1, p2 ];
logp = log( p );
fit_logV_logp( logV, logp );
%-------------------------------------------------------------------------------------------
Re = (1000*V*D)/(0.001);
lambda_E = (p*D)./(0.5*1000*L*V.^2);
lambda_HP = 64./Re;
lambda_W = 1.02*(log10(Re)).^(-2.5);
fit_lambda_Re( Re, lambda_E, lambda_HP, lambda_W );
function [fitresult, gof] = fit_lambda_Re(Re, lambda_E, lambda_HP, lambda_W)
%-------------------------------------------------------------------------------------------
% Plot data.
subplot( 1, 2, 2 );
plot( Re, lambda_E, 'o', MarkerSize=4, MarkerFaceColor='g' );
xscale('log');
yscale('log');
hold on;
%-------------------------------------------------------------------------------------------
[xData, yData] = prepareCurveData( Re, lambda_HP );
% Set up fittype and options.
ft = fittype( 'rat01' );
opts = fitoptions( 'Method', 'NonLinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [64, -1];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
plot( Re, lambda_HP, 'o', MarkerSize=3, MarkerFaceColor='k', MarkerEdgeColor='k' );
h = plot( fitresult );
set(h,LineWidth=1.3,Color='b');
%-------------------------------------------------------------------------------------------
[xData, yData] = prepareCurveData( Re, lambda_W );
% Set up fittype and options.
ft = fittype( 'a*(log10(x)).^(-2.5)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonLinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = 1.02;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
plot( Re, lambda_W, 'o', MarkerSize=3, MarkerFaceColor='k', MarkerEdgeColor='k' );
h = plot( fitresult );
set( h, LineWidth=1.3, Color='r' );
hold off;
%-------------------------------------------------------------------------------------------
% Label axes
title('\lambda vs. Re');
xlabel( 'Re' );
ylabel( '\lambda' );
legend( 'Valores experimentales', 'Valores teóricos', 'Hagen-Poiseuille', '', 'White', 'Location', 'NorthEast', 'Interpreter', 'none' );
grid on;
I've double checked every single line of code of my program but nothing seems to be amiss. I also wasn't able to find anyone else with the same problem. Any help would be appreciated.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Smoothing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


