Curve fitting with two variables

5 ビュー (過去 30 日間)
Kishor Kumar Johari
Kishor Kumar Johari 2021 年 12 月 27 日
コメント済み: William Rose 2022 年 1 月 7 日
Hi community!
I have y = f(x), and z = f(x,y), now i want to fit z vs y and need final graph like z vs y. In general, it can be simply done by replecing x by its y equivalent in z but here it is not possible since x-variable is in the integral.
Thank you for your help!
  11 件のコメント
Kishor Kumar Johari
Kishor Kumar Johari 2022 年 1 月 7 日
@William Rose Thank you so much for the MATLAB code!
I'll try to fit my data using the provided code.
William Rose
William Rose 2022 年 1 月 7 日
@Kishor Kumar Johari, You're welcome. Good luck with your work!

サインインしてコメントする。

回答 (1 件)

William Rose
William Rose 2021 年 12 月 28 日
編集済み: William Rose 2021 年 12 月 28 日
Here is a sample solution. It uses calcZ(), which I posted previously, and it uses the simulated data file which I posted previously. The main program is fitKKJ.m. It calls fmincon() and it passes function sseZY() to fmincon(). Function sseZY is attached. There are comments in fitKKJ.m and in sseZY.m which explain how each works.
Here is the console output when I run the script:
fitKKJ
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
<stopping criteria details>
Best fit values: a=0.771, x=0.047.
The simulated data (ten y,z pairs) was generated with a=1, x=0, and Gaussian noise was added.
The script also plots the measured (or simulated, in this case) data and the best-fit approximation. See plot below.
  1 件のコメント
Kishor Kumar Johari
Kishor Kumar Johari 2022 年 1 月 7 日
@William Rose First of all thank you so much for the efforts you made!
I think there is some confusion about 'x'. It is not a constant of fit, 'a' is only the constant of fit.
'x' is the variable on which 'y' as well as 'z' depends. Here, I would like to explain the problem in detail for more clarity.
There are total four parameters 'x', 'y', 'z', and 'a' are to play. Experimetally, 'y' and 'z' are measured, and 'x' can easily be determined using the equation (2) for each value of 'z' which is corressponding to 'y' . Here, it is to be noted that ultimately we get a dataset for all of three 'x', 'y', 'z'. Now, it is simple when we have to calculate 'a' for only a single set of data, for example we have an experimetally measured z = 0.002 corressponding to y = 3.5, then 'x' can easily be calculated using 'z' like, x = 1.2 (taken arbitrary number for example, not exactly calculated), then using the values of 'z' and 'x', 'a' can simply be calculated.
But the problem arises, when we have to fit a data set with n number of data points, to calculate 'a' as constant of fit.
Now, the problem statement be like we have one input parameter 'x' for generating theoretical data for the fit, and the fit plot should appear 'z' vs 'y'.
Here, it is to be noted that the meaning of the range of 'x' can arbitrarily be given means that an arbitrary data set can be given as input to generate data for 'y' and 'z'.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by