How to extend the curve fitting graph beyond given experiment values?

12 次查看(过去 30 天)
The following below is the code I have generated using Curve fitting option in MATLAB
I NEED TO EXTEND THE FITTED CURVE BEYOND THE GIVEN X AND Y VALUES UNTIL X VALUE OF 10 LAKH.
ALSO HOW TO FIND THE Y VALUE IF I HAVE THE CORRESPONDING X VALUE? i HAVE R_f AS 151.3 FROM
THE RESULT OF CURVE FITTING BUT i NEED TO FIND THE y VALUE CORRESPONDING TO 151.3?
tHE problem is with the highlighted portions of the code. Can someone please help?
function [fitresult, gof] = FXVol(x, y)
%CREATEFIT(X,Y)
% Create a fit.
%
% Data for 'Fredlund-XIng(1994)-Vvspsi' fit:
% X Input : x
% Y Output: y
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 29-Jul-2021 13:22:43
%% Fit: 'Fredlund-XIng(1994)-Vvspsi'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( '(1-((log(1+(x/R_F)))/(log(1+(1000000/R_F)))))*(S_F/(log(2.72+(x/a_F)^n))^m)', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 0 0 0];
opts.StartPoint = [0.278498218867048 0.546881519204984 0.957506835434298 0.157613081677548 0.970592781760616];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Fredlund-XIng(1994)-Vvspsi' );
x=linspace(1,1000000);
yhat=(1-((log(1+(x/fitresult.R_F)))/(log(1+(1000000/fitresult.R_F)))))*(fitresult.S_F/(log(2.72+(x/fitresult.a_F)^fitresult.n))^fitresult.m);
plot(x,yhat); %As before
hold on;
plot( fitresult, xData, yData );
set(gca,'XScale','log');
xlim([1,1000000]);
% Label axes
xlabel( 'Matric Suction (kPa)', 'Interpreter', 'none' );
ylabel( 'Volumetric Water Content (%)', 'Interpreter', 'none' );
grid on
index = find(X==151.3);
Y_point = Y(index);

回答(1 个)

Animesh
Animesh 2024-2-23
It looks like you are trying to extend the fitted curve to an x value 1,000,000 and find a corresponding y value for a specific x value (R_f = 151.3).
We can use the “fitresult” to predict the “y” values of the extended range of “x” values. The “feval’ function in MATLAB can be used for this and can also be used to get the “y” value for a specific “x” value (in this case, R_f = 151.3).
Here is something we can do to achieve the same:
function [fitresult, gof] = FXVol(x, y)
% ... [your code] ...
% Extend the range of x values up to 1000000
extended_x = linspace(min(xData), 1000000, 1000);
% Evaluate the fitted model at the extended range of x values
extended_y = feval(fitresult, extended_x);
% Plot the extended fit with data
figure('Name', 'Fredlund-XIng(1994)-Vvspsi');
plot(extended_x, extended_y, 'r-', 'LineWidth', 2); % Extended fit
hold on;
plot(fitresult, xData, yData); % Original data and fit
set(gca, 'XScale', 'log');
xlim([min(xData), 1000000]);
% ... [plotting code] ...
% Find the y value corresponding to R_f = 151.3
R_f = 151.3;
Y_point = feval(fitresult, R_f);
disp(['The y value corresponding to R_f = ', num2str(R_f), ' is: ', num2str(Y_point)]);
end
You can refer to the following MathWorks documentations to get more details on the “fevel” function:

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by