이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
fitting with y and x dependent variables
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Torsten
2022년 6월 13일
So you want to minimize
sum_i [(Xi*Xc - xi).^2 + (Yi*Yc - yi).^2]
in which Xc and Yc are the fitting parameters and X, Y, x, y are given vectors ?
Torsten
2022년 6월 13일
@laurent jalabert comment moved here:
Yes, what you wrote is the minimum vector length between data and target array of normalized data.
Notice that x and y vectors have different length compared to X and Y.
Torsten
2022년 6월 13일
Notice that x and y vectors have different length compared to X and Y.
Why ?
I thought X = x / Xc and Y = y / Yc where Xc and Yc are scalars. Thus x and X as well as y and Y should have the same length.
Torsten
2022년 6월 13일
@laurent jalabert comment moved here:
first of all, thank you so much to take your time to answer my problem.
You are right, they should have same length. But in the real life of experiments, x and y have less available data point, compared to what computers can output from complicated model. That is why x,y have not same dimension than X and Y.
Torsten
2022년 6월 13일
Please use the "comment" button instead of the "answer" button when you want to make comments.
Torsten
2022년 6월 13일
편집: Torsten
2022년 6월 13일
That is why x,y have not same dimension than X and Y.
Then you should supply only those X and Y data that correspond to the x and y experimental data.
E.g. if x and y were time-dependent experimental data measured at times t, then you also should only use those X and Y data at the times t of the experimental measurements for the fitting process.
Is this possible ?
Image Analyst
2022년 6월 13일
@laurent jalabert If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
laurent jalabert
2022년 6월 13일
[I am in the comment domain]
x,y are not time dependent data. Xc and Yc are 2 parameters that have to be found as fitting parameters, in order (as you said) to minimize the distance between experimental points and an universal curve provided as a 2 columns array of X = x/Xc and Y = y/Yc. I know X and Y, I know x and y, but I do not know Xc and Yc.
The "shape" of y versus x is about the same than the shape of Y versus X, and a x-axis sliding and y-axis sliding factors that are Xc and Yc.
I am pretty sure that a non linear regression fitting might be programmable, but I do not know how to declare a variable in the x area.
Another approach I though is to plot the universal Y versus X on a graph, and to plot the x and y data. If there was a sliding in x-axis and a sliding in y-axis so that graphically I can superpose the 2 curves, then get the sliding factors, this might be a first approach to solve the problem, even it is not the most relevant.
laurent jalabert
2022년 6월 13일
편집: laurent jalabert
2022년 6월 13일
OK for the tutorial, I am using this forum for several 20 years maybe. If I post something, that is because it is not trivial. You can find maybe an appropriate way of solving this problem if you master Mathematica where some optimization functions are native. But with Matlab, at some point, the fitting is becoming very complicated, especially for the problem that I am presenting in this post.
In order to have a better understanding, I post (as requested) the theory and a set of my experimental data. OK I admit that I should provide real/Imag parts for both, but it does not change the core of the fitting problem.
Theory.xlsx : Column 1 is X, column 2 is Real(Y), and column 3 is Imag(Y). Those are the universal curves for real and imaginary parts of complex Y.
Experiment.xlsx : I attached a set of experimental data x and y, where column 1 is x, column 2 is the amplitude(y) and column 3 is the phase(y).
y = real(y) + imag(y) = amplitude(y).*exp(i*phase(y))
This slider_plot could have been interesting to slide the experimental points until matching the theory curve, but I could not succeed to use it correctly. This is just a quick way to estimage Xc and Yc. But this is not optimized.
https://fr.mathworks.com/matlabcentral/answers/374973-update-plot-based-on-two-sliders
laurent jalabert
2022년 6월 15일
Is it doable with Matlab ?
I have an array of theoretical data that are x/Xc and y/Yc.
In my experiment, I measure x and y, and I want to find Xc and Yc to fit this curve with the theroretical array above.
I don't know Xc and Yc a priori. I know that if I multiply x by a certain 1/Xc and if I multiply y by a certain 1/Yc, then I can be closed to the theoretical array.
Torsten
2022년 6월 15일
편집: Torsten
2022년 6월 15일
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
2022년 6월 15일
편집: laurent jalabert
2022년 6월 16일
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)
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)