%我正在尝试使用 MATLAB 中的 van Genuchten 模型绘制土壤保水曲线。 %我已从 Excel 文件加载数据并应用模型方程。然而,我在将模型拟合到观察到的 theta 值并绘制结果方面面临着问题。这是代码:
% Load data from Excel file
` EV = readtable('Retention.xlsx', 'Sheet', 1);
CB1 = EV(1:38, :);`your text`
theta = CB1.SWC_A / 100; % to change the data in decimale point
h = CB1.psi;`
% Parameters obtained from previous experiments
` theta_r = 0.070; % Residual water content
theta_s = 0.434; % Saturated water content
alpha = -3.402; % air-entry value
n = 0.3273; % Pore size distribution parameter
m = 3.4195; % Empirical parameter`
%Calculate theta_c using the model equation ((van Genuchten model)
`theta_c = theta_r + ((theta_s - theta_r) ./ (1 + alpha * abs(h)).^n).^m;`
% Fitting the model to the observed theta values (not theta_c)
`fitType = fittype('a * (x^b)');
fitOptions = fitoptions(fitType);
fitOptions.StartPoint = [1 1];
fittedModel = fit(h, theta, fitType, fitOptions);`
% Calculate fitted theta values using the fitted model
`fittedTheta = fittedModel(h);
%Plotting
`figure;
hold on;
scatter(h, theta, 'filled', 'DisplayName', 'Data');
plot(h, fittedTheta, 'r-', 'LineWidth', 1); % Fitted curve
xlabel('Pressure Head (h)');
ylabel('Volumetric Moisture Content (\theta)');
legend('Location', 'SouthEast');
box on;%%% `
%(https://i.stack.imgur.com/ZG5pz.png)
您的样本数据没有排序,因此当您重新使用 x 轴的粗略
h
值时,它实际上是随机来回的。对于散点图来说并不重要,但对于画线来说就不是我们想要的了。
拟合曲线的要点是我们没有脱离采样的分析函数,那么,为什么要使用粗分散的 x 轴值呢? 您只需创建一个新值的线性空间来绘制
fittedModel
h_smooth = linspace(min(h), max(h), 1000); % for a nice smooth plot
fittedTheta = fittedModel(h_smooth);
figure;
hold on;
scatter(h, theta, 'filled', 'DisplayName', 'Data');
plot(h, fittedTheta, 'r-', 'LineWidth', 1);
...