nonlinear regression for multiple variable parameter
显示 更早的评论
I'm trying to write code to perform a nonlinear regression with multiple variables, but i have no idea how to do it.
i need to use Keq and pressure like Xdata and define the x1,x2,x3 from the regression.
I hope I have explained myself.
Function value and YDATA sizes are not equal.
Error in prova3 (line 49)
x_fit = lsqcurvefit(T, x0, [pressure Keq], temperature);
clc
clear all
close all
%%
%read all .xlsx file inside the folder
path = dir('C:\Users\Andrea\Desktop\matlab\input_file\*.xlsx');
%cicle for obtain the sample data (P-T-Ni) content directly from the .xlsx file
for i=1:1
table = readtable(strcat('C:\Users\Andrea\Desktop\matlab\input_file\',path(i).name));
temperature(:,i) = table.temperature;
pressure(:,i) = table.pressure;
Ni_grt(:,i) = table.Ni_Grt;
Ni_ol(:,i) = table.Ni_Ol;
Cr_grt(:,i) = table.Wt_Cr;
Ca_grt(:,i) = table.Wt_Ca;
end
%% calculation
%Keq
Ni_grt = Ni_grt(~isnan(Ni_grt), :);
Keq= log(Ni_grt/2900);
%temperature from C to K
temperature = temperature + 273.15;
%olivine mean
Ni_ol = Ni_ol(~isnan(Ni_ol), :);
mean_Ni_ol = mean(Ni_ol);
%% ignore the NaN value
temperature = temperature(~isnan(temperature), :);
pressure = pressure(~isnan(pressure), :);
Ca_grt = Ca_grt(~isnan(Ca_grt), :);
Cr_grt = Cr_grt(~isnan(Cr_grt), :);
%% Calculate the parameters (ΔH, ΔV, ΔS)
% function of T
T = @(x,pressure,Keq) (x(1) + pressure * x(2)) ./ (x(3) - log(Keq));
% random start parameters (ΔH, ΔV, ΔS)
x0 = [1, 1, 1];
% nonlinear regression with lsqcurvefit
x_fit = lsqcurvefit(T, x0, [pressure Keq], temperature);
% Extract the fitted parameters
DeltaH = x_fit(1);
DeltaV = x_fit(2);
DeltaS = x_fit(3);
% the new value od temperature from Ni_grt of database
predicted_temperature = T(x_fit, pressure);
% print the result
fprintf('Parametri adattati:\n');
fprintf('ΔH = %.2f\n', DeltaH);
fprintf('ΔV = %.2f\n', DeltaV);
fprintf('ΔS = %.2f\n', DeltaS);
fprintf('Ni_ol = %.2f\n', mean_Ni_ol);
%% diff TNi-T
deltaT = predicted_temperature-temperature;
mean_deltaT = mean(deltaT);
fprintf('mean_detaT = %.2f\n', mean_deltaT);
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!