fitting with y and x dependent variables

2 views (last 30 days)
I have 2 columns of universal data X and Y. I can plot an universal Y as a function of X.
Now, X = x / Xc. And Y = y / Yc.
x and y are my experimental data.
Xc and Yc are the fitting parameters that I need to retrieve. In other word, I need to find Xc and Yc in order to minimize the difference between the Y versus X (that I know) and the y*Yc versus x*Xc
How can I do that ?
  14 Comments
Torsten
Torsten on 15 Jun 2022
Edited: Torsten on 15 Jun 2022
Suppose you are given Xc and Yc.
Then you can calculate x/Xc and y/Yc.
Now with which X and Y value do you want to compare x/Xc and y/Yc in the optimization process ?
Taking the X that is nearest to x/Xc and the corresponding Y in the table of theory data to compare with y/Yc ?
Or taking the Y value that is nearest to y/Yc and the corresponding X in the table of theory data to compare with x/Xc ?
Or ...
laurent jalabert
laurent jalabert on 15 Jun 2022
Edited: laurent jalabert on 16 Jun 2022
Now with which X and Y value do you want to compare x/Xc and y/Yc in the optimization process ?
--> X and Y data from the column 1 and 2 of the file theory.xlsx
x,y are experimental data. Xc and Yc are fitting parameters that I want to output. But the model for fitting is not a function, it is array of theoretical points X and Y, with X = x/Xc and Y=y/Yc.
To feel what I what to do, yes, you can define Xc and Yc arbitrary, and plot scaled data (by Xc and Yc) and theory in order to see if it matches or not. I recommend log scale display. If you do that, intuitively, you will find Xc about 100 and Yc about 3.5. But this is indeed not accurate nor optimized.
Now, what I want to do can be done in Mathematica but I want to use Matlab to include this fit into my main data analysis program (already 4000 lines of code).
Basically, in Mathematica, the steps are like this :
1- load theoretical data column 1 (x/Xc) and 2 (real part y/Yc) % data_theo(:,1) and data_theo(:,2)
2- import experimental data x and y
3- define RP as interpolation order 1 of the table of experimental data (x, y) to the length of theoretical vector length(data_theo(:,1)); I can use linspace or logspace.
4- (important) define modelR = Yc * RP[x/Xc] ; % RP as a function of x/Xc
5- fittingR = Quiet[NonlinearModelFit[y, {modelR, {Yc > 0, Xc > 0}}, {Yc, Xc}, x]];
non linear regression fit on data y, using the interpolation modelR, for Yc positive and Xc positive, {Yc,Xc} being the 2 fitting parameters, and x the abscisse from experimental data.
By using Mathematica with the set of data that I provided, the output parameters are Yc = 3.05 with std=0.0122, and Xc = 187.696 with std = 4.025, for a fit R^2 = 0.999944.
Now, on Matlab, I think that I should use griddedinterpolant or scatteredinterpolant .
For point 4, How to define the modelR as a function of the interpolation function that depends on x/Xc (Xc a fit parameter) i.e how to translate the modelR that included RP[x/Xc] in Matlab code ?
modelR = @({Yc,Xc},x) Yc*RP[x/Xc]
% point 1
ds_theo = spreadsheetDatastore('/Users/name/Desktop/theory.xlsx',"FileExtensions",[".xlsx",".xls"]);
data_theo = table2array(read(ds_theo));
% point 2
ds_exp = spreadsheetDatastore('/Users/name/Desktop/experiment.xlsx',"FileExtensions",[".xlsx",".xls"]);
data_exp = table2array(read(ds_exp));
% point 3
% RP = scatteredInterpolant(data_exp,data_theo) ; % does not work
%% plot
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
nbfig = size(FigList,1);
fig(nbfig+1) = figure('PaperUnits','inches','PaperType','A4','PaperOrientation',...
'landscape','Color',[1 1 1], 'OuterPosition',[1 1 600 600]);
semilogx(data_theo(:,1),data_theo(:,2),'LineWidth',2);
hold on
semilogx(data_theo(:,1),data_theo(:,3),'LineWidth',2);
grid on
% plot experimental data
hold on
semilogx(data_exp(5:end,1),data_exp(5:end,2),'o','LineWidth',2);
hold on
semilogx(data_exp(5:end,1),wrapTo2Pi(data_exp(5:end,3)),'o','LineWidth',2);
legend('theo RP','theo IM','exp RP','exp IM')
set(gca,'FontSize',14,'LineWidth',1)

Sign in to comment.

Answers (0)

Categories

Find more on Historical Contests in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!